Skip to content

support psql commands #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mmoncure opened this issue Apr 14, 2025 · 1 comment · Fixed by #336
Closed

support psql commands #335

mmoncure opened this issue Apr 14, 2025 · 1 comment · Fixed by #336
Assignees
Labels
bug Something isn't working

Comments

@mmoncure
Copy link

mmoncure commented Apr 14, 2025

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
@mmoncure mmoncure added the bug Something isn't working label Apr 14, 2025
@psteinroe
Copy link
Collaborator

Good point, will add that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants