ctags-lang-sql(7)
π 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 π
- [PL] PostgreSQL 9.5.25 Documentation, "Chapter 39. Procedural Languages", <https://www.postgresql.org/docs/9.5/xplang.html>
- [GH3006] @bagl's comment submitted to <https://github.com/universal-ctags/ctags/issues/3006>
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
- ubuntu resolute: universal-ctags 6.2.1-1 Β· GPL-2.0-or-later
- ubuntu stonking: universal-ctags 6.2.1-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms