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/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect output when identifier with escaped quote used in select alias

zenazn opened this issue · comments

$ 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"""

Commit 24c8203 fixes this issue.