1CTAGS-LANG-SQL(7)               Universal Ctags              CTAGS-LANG-SQL(7)
2
3
4

NAME

6       ctags-lang-sql - The man page of the SQL parser for Universal Ctags
7

SYNOPSIS

9       ctags ... [--extras={guest}] --languages=+SQL ...
10
11

DESCRIPTION

13       The  SQL  parser  supports  various  SQL dialects. PostgreSQL is one of
14       them.
15
16       PostgreSQL allows user-defined functions to be written  in  other  lan‐
17       guages (procedural languages) besides SQL and C [PL].
18
19       The  SQL  parser  makes  tags  for language objects in the user-defined
20       functions written in the procedural languages if the guest extra is en‐
21       abled.
22
23       The  SQL  parser looks for a token coming after LANGUAGE keyword in the
24       source code to choose a proper guest parser.
25
26          ... LANGUAGE plpythonu AS '... user-defined function ' ...
27          ... AS $$ user-defined function $$ LANGUAGE plv8 ...
28
29       In the above examples, plpythonu and plv8 are the names  of  procedural
30       languages. The SQL parser trims pl at the start and u at the end of the
31       name before finding a ctags parser.  For plpythonu and  plv8,  the  SQL
32       parser extracts python and v8 as the candidates of guest parsers.
33
34       For  plpythonu,  ctags can run its Python parser.  ctags doesn't have a
35       parser named v8. However, the JavaScript parser in ctags has v8  as  an
36       alias.  So  ctags can run the JavaScript parser as the guest parser for
37       plv8.
38

EXAMPLES

40       tagging code including a user-defined  function  in  a  string  literal
41       [GH3006]:
42
43       "input.sql"
44
45          CREATE OR REPLACE FUNCTION fun1() RETURNS VARCHAR AS '
46          DECLARE
47                  test1_var1 VARCHAR(64) := $$ABC$$;
48                  test1_var2 VARCHAR(64) := $xyz$XYZ$xyz$;
49                  test1_var3     INTEGER := 1;
50          BEGIN
51                  RETURN  TO_CHAR(test_var3, ''000'') || test1_var1 || test1_var2;
52          END;
53          ' LANGUAGE plpgsql;
54
55       "output.tags" with "--options=NONE -o - --sort=no --extras=+{guest} in‐
56       put.sql"
57
58          fun1    input.sql       /^CREATE OR REPLACE FUNCTION fun1() RETURNS VARCHAR AS '$/;"    f
59          test1_var1      input.sql       /^      test1_var1 VARCHAR(64) := $$ABC$$;$/;"  v
60          test1_var2      input.sql       /^      test1_var2 VARCHAR(64) := $xyz$XYZ$xyz$;$/;"    v
61          test1_var3      input.sql       /^      test1_var3     INTEGER := 1;$/;"        v
62
63       tagging code including  a  user-defined  function  in  a  dollar  quote
64       [GH3006]:
65
66       "input.sql"
67
68          CREATE OR REPLACE FUNCTION fun2() RETURNS VARCHAR LANGUAGE plpgsql AS $$
69          DECLARE
70                  test2_var1 VARCHAR(64) := 'ABC2';
71                  test2_var2 VARCHAR(64) := 'XYZ2';
72                  test2_var3        INTEGER := 2;
73          BEGIN
74                  RETURN  TO_CHAR(test2_var3, '000') || test2_var1 || test2_var2;
75          END;
76          $$;
77
78       "output.tags" with "--options=NONE -o - --sort=no --extras=+{guest} in‐
79       put.sql"
80
81          fun2    input.sql       /^CREATE OR REPLACE FUNCTION fun2() RETURNS VARCHAR LANGUAGE plpgsql AS $\$$/;" f
82          test2_var1      input.sql       /^      test2_var1 VARCHAR(64) := 'ABC2';$/;"   v
83          test2_var2      input.sql       /^      test2_var2 VARCHAR(64) := 'XYZ2';$/;"   v
84          test2_var3      input.sql       /^      test2_var3        INTEGER := 2;$/;"     v
85
86       tagging code including a user-defined written in JavaScript:
87
88          -- Derived from https://github.com/plv8/plv8/blob/r3.0alpha/sql/plv8.sql
89          CREATE FUNCTION test(keys text[], vals text[]) RETURNS text AS
90          $$
91                  var o = {};
92                  for (var i = 0; i < keys.length; i++)
93                          o[keys[i]] = vals[i];
94                  return JSON.stringify(o);
95          $$
96          LANGUAGE plv8 IMMUTABLE STRICT;
97
98       "output.tags" with "--options=NONE -o - --sort=no --extras=+{guest} in‐
99       put.sql"
100
101          test    input.sql       /^CREATE FUNCTION test(keys text[], vals text[]) RETURNS text AS$/;"    f
102          o       input.sql       /^      var o = {};$/;" v
103

KNOWN BUGS

105       Escape  sequences ('') in a string literal may make a guest parser con‐
106       fused.
107

SEE ALSO

109       ctags(1), ctags-client-tools(7)
110

REFERENCES

112       [PL] PostgreSQL 9.5.25  Documentation,  "Chapter  39.  Procedural  Lan‐
113            guages", https://www.postgresql.org/docs/9.5/xplang.html
114
115       [GH3006]
116            @bagl's              comment              submitted             to
117            https://github.com/universal-ctags/ctags/issues/3006
118
119
120
121
1225.9.0                                                        CTAGS-LANG-SQL(7)
Impressum