darold / pgFormatter

A PostgreSQL SQL syntax beautifier that can work as a console program or as a CGI. On-line demo site at http://sqlformat.darold.net/
PostgreSQL License
1.66k stars 100 forks source link

[Bug] Formatting "exists" statement #336

Closed bogdan closed 5 months ago

bogdan commented 5 months ago

Any use of EXISTS keyword causes an error:

$ echo "SELECT * FROM companies WHERE EXISTS (SELECT 1)" | pg_format
Uncaught exception: Use of uninitialized value in pattern match (m//) at /usr/local/Cellar/pgformatter/5.5/libexec/lib/pgFormatter/Beautify.pm line 968, <STDIN> line 1.
 at /usr/local/bin/pg_format line 19, <STDIN> line 1.
    main::__ANON__("Use of uninitialized value in pattern match (m//) at /usr/loc"...) called at /usr/local/Cellar/pgformatter/5.5/libexec/lib/pgFormatter/Beautify.pm line 968
    pgFormatter::Beautify::beautify(pgFormatter::Beautify=HASH(0x7f7996c273f8)) called at /usr/local/Cellar/pgformatter/5.5/libexec/lib/pgFormatter/CLI.pm line 170
    pgFormatter::CLI::beautify(pgFormatter::CLI=HASH(0x7f799600be28)) called at /usr/local/Cellar/pgformatter/5.5/libexec/lib/pgFormatter/CLI.pm line 78
    pgFormatter::CLI::run(pgFormatter::CLI=HASH(0x7f799600be28)) called at /usr/local/bin/pg_format line 49
stefanvanburen commented 5 months ago

Just hit a similar failure. FWIW, adding the ; at the end fixes things:

$ echo "SELECT * FROM companies WHERE EXISTS (SELECT 1);" | pg_format
SELECT
    *
FROM
    companies
WHERE
    EXISTS (
        SELECT
            1);
darold commented 5 months ago

I'm not able to reproduce the problem using latest development code:

$ echo "SELECT * FROM companies WHERE EXISTS (SELECT 1)" | pg_format
SELECT
    *
FROM
    companies
WHERE
    EXISTS (
        SELECT
            1)
stefanvanburen commented 5 months ago

yeah, I was definitely on v5.5.

mijoharas commented 5 months ago

Ahhh should have checked the issues in more detail. I ran into this as well, reduced it to the EXISTS and figured out that the semi-colon at the end fixed it. I've checked, and it's v5.5 where I'm hitting the issue. Let me just double check latest devel.

Yep, can confirm that the issue is fixed (for me) on the latest master.

Are there any plans to cut a release any time soon?

darold commented 5 months ago

I can try to push a new release this weekend.

tobez commented 1 month ago

Was a new release that fixes this ever made?