Closed
Description
psql commands \if, \set etc are normal to see in .sql source files in order to support certain kinds of build managements systems. Currently they are thrown out as unrecognized. I guess this is a bit of a stretch to be called a bug, but in general the checker should parse .sql that psql can parse. backslash commands are very simple; if the first character of a line is a backslash the rest of the line can be ignored. I not believe there is any need to interpret the commands.
To Reproduce
This file:
psql_test.sql
\if 1
do $$
begin
raise notice '%', $q$
\this is in a string;
$q$;
end;
$$;
\endif
...yields...
./psql_test.sql:1:1 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid statement: syntax error at or near "\"
> 1 │ \if 1
│ ^^^^^
2 │
3 │ do $$
./psql_test.sql:12:5 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid statement: syntax error at or near "\"
10 │ $$;·
11 │
> 12 │ \endif
│ ^^^^^^
13 │
Checked 1 file in 3ms. No fixes applied.
Found 2 errors.
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Some errors were emitted while running checks.
psql however yields:
NOTICE:
\this is in a string;
DO