ctags-lang-sql(7)

πŸ“¦
version 6.2.1 Β· 3 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– ctags-lang-sql πŸ’–

okay bestie, this is the manual page for ctags-lang-sql β€” literally the SQL parser for Universal Ctags. yes, the whole thing. grab a snack, we're going in πŸ“


✨ NAME ✨

ctags-lang-sql β€” The man page of the SQL parser for Universal Ctags πŸ’…


✨ SYNOPSIS ✨

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

✨ DESCRIPTION ✨

so the SQL parser? it supports a whole bunch of SQL dialects. PostgreSQL is one of them, and she's kind of the main character here πŸ‘‘

ngl, PostgreSQL lets you write user-defined functions in other languages β€” procedural languages β€” not just SQL and C [PL]. iconic behaviour honestly.

and here's the slay: the SQL parser will make tags for language objects inside those user-defined functions, as long as the guest extra is enabled. yes really. it's giving bilingual queen πŸ¦‹

how does it know which parser to summon? it looks for the token that comes right after the LANGUAGE keyword in your source, and picks the right guest parser from that:

... LANGUAGE plpythonu AS '... user-defined function ' ...
... AS $$ user-defined function $$ LANGUAGE plv8 ...

in those examples, plpythonu and plv8 are the names of procedural languages. so what does the SQL parser do? it trims pl off the front and u off the back of the name before it goes looking for a ctags parser. so for plpythonu and plv8, it pulls out python and v8 as the guest parser candidates ✨

for plpythonu, ctags can just run its Python parser, easy. but ctags doesn't have a parser named v8. plot twist! 😭 however β€” the JavaScript parser in ctags has v8 as an alias. so ctags can run the JavaScript parser as the guest parser for plv8. we love a plot resolution πŸ’–


✨ EXAMPLES ✨

🌸 tagging code including a user-defined function in a string literal [GH3006] 🌸

"input.sql"

CREATE OR REPLACE FUNCTION fun1() RETURNS VARCHAR AS '
DECLARE
    test1_var1 VARCHAR(64) := $$ABC$$;
    test1_var2 VARCHAR(64) := $xyz$XYZ$xyz$;
    test1_var3     INTEGER := 1;
BEGIN
    RETURN  TO_CHAR(test_var3, ''000'') || test1_var1 || test1_var2;
END;
' LANGUAGE plpgsql;

"output.tags" with --options=NONE -o - --sort=no --extras=+{guest} input.sql

fun1    input.sql    /^CREATE OR REPLACE FUNCTION fun1() RETURNS VARCHAR AS '$/;"    f    typeref:typename:VARCHAR
test1_var1    input.sql    /^    test1_var1 VARCHAR(64) := $$ABC$$;$/;"    v
test1_var2    input.sql    /^    test1_var2 VARCHAR(64) := $xyz$XYZ$xyz$;$/;"    v
test1_var3    input.sql    /^    test1_var3     INTEGER := 1;$/;"    v

🌈 tagging code including a user-defined function in a dollar quote [GH3006] 🌈

"input.sql"

CREATE OR REPLACE FUNCTION fun2() RETURNS VARCHAR LANGUAGE plpgsql AS $$
DECLARE
    test2_var1 VARCHAR(64) := 'ABC2';
    test2_var2 VARCHAR(64) := 'XYZ2';
    test2_var3        INTEGER := 2;
BEGIN
    RETURN  TO_CHAR(test2_var3, '000') || test2_var1 || test2_var2;
END;
$$;

"output.tags" with --options=NONE -o - --sort=no --extras=+{guest} input.sql

fun2    input.sql    /^CREATE OR REPLACE FUNCTION fun2() RETURNS VARCHAR LANGUAGE plpgsql AS $\$$/;"    f    typeref:typename:VARCHAR
test2_var1    input.sql    /^    test2_var1 VARCHAR(64) := 'ABC2';$/;"    v
test2_var2    input.sql    /^    test2_var2 VARCHAR(64) := 'XYZ2';$/;"    v
test2_var3    input.sql    /^    test2_var3        INTEGER := 2;$/;"    v

πŸ’œ tagging code including a user-defined written in JavaScript πŸ’œ

-- Derived from https://github.com/plv8/plv8/blob/r3.0alpha/sql/plv8.sql
CREATE FUNCTION test(keys text[], vals text[]) RETURNS text AS
$$
    var o = {};
    for (var i = 0; i < keys.length; i++)
        o[keys[i]] = vals[i];
    return JSON.stringify(o);
$$
LANGUAGE plv8 IMMUTABLE STRICT;

"output.tags" with --options=NONE -o - --sort=no --extras=+{guest} input.sql

test    input.sql    /^CREATE FUNCTION test(keys text[], vals text[]) RETURNS text AS$/;"    f
o    input.sql    /^    var o = {};$/;"    v

⚠️ KNOWN BUGS ⚠️

Escape sequences ('') in a string literal may make a guest parser confused. 😭 yeah. it happens. don't come for her, she's doing her best.

πŸ” SEE ALSO πŸ”

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


πŸ“š REFERENCES πŸ“š


and that's the whole page, bestie!! 🫢 this was Universal Ctags version 6.2.1 of the ctags-lang-sql(7) manual page β€” go forth and tag your procedural-language functions, you absolute legend πŸ‘‘πŸ’–

πŸ“¦ where this page comes from