Skip to content
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

Missing quoting in 'Alias' deparse #17

Open
benny-medflyt opened this issue Mar 5, 2020 · 4 comments
Open

Missing quoting in 'Alias' deparse #17

benny-medflyt opened this issue Mar 5, 2020 · 4 comments

Comments

@benny-medflyt
Copy link

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:

if (node.colnames) {
output.push(name + parens(this.list(node.colnames)));
} else {
output.push(this.quote(name));
}

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
Copy link
Author

I found a similar problem with SQL OVER clauses:

if (context !== 'window') {
if (node.name) {
output.push(node.name);
}
}

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

@pyramation
Copy link

@benny-medflyt is this still an issue?

@pyramation
Copy link

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

pyramation added a commit to pyramation/pg-query-parser that referenced this issue Jun 11, 2020
@pyramation
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants