Function with sql as language yields a false syntax error
svnv opened this issue · comments
Valid sql function:
CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
Output from pgsanity:
$ pgsanity valid_function.sql
line 3: ERROR: syntax error at or near "SQL"
Sven,
Thanks for submitting the issue. I'm going to blame this one on ecpg. What I discovered is that if you put the language name within single quotes then ecpg (and thereby pgsanity) will report correct syntax. By skimming through the postgresql documentation I see this in the 9.1 docs:
"For backward compatibility, the name can be enclosed by single quotes."
...and the following, harsher language, in the 9.5 (latest) docs:
"Enclosing the name in single quotes is deprecated and requires matching case."
I experimented with fixing the case to match "sql" rather than "SQL", but ecpg seems to consistently fail when there are no quotes around the language name. I did my testing with an ecpg that reports its version as "ecpg (PostgreSQL 9.4.5) 4.10.0".
I'd like to avoid working around ecpg issues in pgsanity. I would recommend that you throw some quotes around the name of the language for now - hopefully this will get fixed in ecpg shortly.