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

Incorrect output when identifier with escaped quote used in select alias #299

Closed zenazn closed 1 year ago

zenazn commented 1 year ago
$ psql
psql (11.18)
Type "help" for help.

carl=# select 1 as "x""";
 x"
----
  1
(1 row)

But that query formats to:

$ pg_format --version
pg_format version 5.3
$ echo 'select 1 as "x"""' | pg_format
select
  1 as "x" ""

Which predictably does not work:

carl=# select
  1 as "x" "";
ERROR:  zero-length delimited identifier at or near """"
LINE 2:   1 as "x" "";
                   ^

I believe the correct way to format this query is

select
  1 as "x"""
darold commented 1 year ago

Commit 24c8203 fixes this issue.