pgsql-ast-parser
pgsql-ast-parser copied to clipboard
"RETURNS SETOF record LANGUAGE" causes error
CREATE OR REPLACE FUNCTION schema_identifier_split(url_path TEXT, OUT scope TEXT, OUT plugin TEXT, OUT name TEXT, OUT version INT)
RETURNS SETOF record LANGUAGE plpgsql AS $$
DECLARE
parts TEXT[];
BEGIN
parts := string_to_array(url_path, '/');
scope := parts[1];
plugin := parts[2];
name := parts[3];
IF array_length(parts, 1) > 3 THEN
version := parts[4]::INT;
ELSE
version := NULL;
END IF;
RETURN NEXT;
END;
$$;
error: Uncaught (in promise) Error: Syntax error at line 2 col 22:
RETURNS SETOF record LANGUAGE
^
Unexpected word token: "language". I did not expect any more input. Here is the state of my parse table:
kw_returns → %word ●
word → %word ●
kw_language → %word ●
func_spec$subexpression$2 → word ●
func_spec$subexpression$5 → word ●
func_spec$subexpression$4 → word ●
func_spec$subexpression$3 → word ●
func_purity → word ●
var err = new Error(this.reportError(token));
^
at Parser.feed (https://deno.land/x/[email protected]/lib/nearley.js:337:27)
at _parse (https://deno.land/x/[email protected]/parser.ts:110:16)
at doParse (https://deno.land/x/[email protected]/parser.ts:57:27)
at parse (https://deno.land/x/[email protected]/parser.ts:60:11)
at getSQLFile (file:///Users/thomasreggi/Documents/GitHub/pgrun/mod.ts:35:28)
at readSqlFile (file:///Users/thomasreggi/Documents/GitHub/pgrun/mod.ts:74:10)
at eventLoopTick (ext:core/01_core.js:183:11)
at async Promise.all (index 45)
at async readSQLFiles (file:///Users/thomasreggi/Documents/GitHub/pgrun/mod.ts:86:17)
at async organizer (file:///Users/thomasreggi/Documents/GitHub/pgrun/mod.ts:266:17)
It seems this is not limited to "LANGUAGE," but rather an issue with SETOF. The following also errors:
RETURNS SETOF refcursor