pg-query-parser icon indicating copy to clipboard operation
pg-query-parser copied to clipboard

Missing quoting in 'Alias' deparse

Open benny-medflyt opened this issue 5 years ago • 4 comments

There is a bug in the deparse function when outputting an Alias that has colnames. It doesn't properly quote the alias name and the column names:

https://github.com/zhm/pg-query-parser/blob/1684b8f7147a189728297997661b48baf4c0534c/src/deparser.js#L269-L273

The fix is to call this.quote on the name (just as is done in the "else" branch) as well as this.quote on all the column names.

Here are 2 valid PostgreSQL queries that this library parses correctly, but deparse generates invalid output:

SELECT * FROM generate_series(1, 1) "a#b";

SELECT * FROM generate_series(1, 1) "a#b"("c#d");

Incorrectly is deparsed to:

SELECT * FROM generate_series(1, 1) AS a#b;

SELECT * FROM generate_series(1, 1) AS a#b(c#d);

I can try to create a pull request

benny-medflyt avatar Mar 05 '20 16:03 benny-medflyt

I found a similar problem with SQL OVER clauses:

https://github.com/zhm/pg-query-parser/blob/1684b8f7147a189728297997661b48baf4c0534c/src/deparser.js#L1115-L1119

It should be output.push(this.quote(name));

benny-medflyt avatar Mar 10 '20 14:03 benny-medflyt

@benny-medflyt is this still an issue?

pyramation avatar Jun 04 '20 23:06 pyramation

if it is, make a PR to my fork and I'll merge and publish https://github.com/pyramation/pgsql-parser

pyramation avatar Jun 05 '20 00:06 pyramation

@benny-medflyt fixed: https://github.com/pyramation/pgsql-parser/commit/ec36490546712b9301b0ef4a87f7fdf46a7f9453

pyramation avatar Jun 11 '20 04:06 pyramation