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

Queries with Postgres crosstab function could not be parsed #849

Closed
sivaraam opened this issue Sep 10, 2019 · 3 comments
Closed

Queries with Postgres crosstab function could not be parsed #849

sivaraam opened this issue Sep 10, 2019 · 3 comments

Comments

@sivaraam
Copy link
Contributor

sivaraam commented Sep 10, 2019

Describe the bug
Trying to parse a query with crosstab function of Postgres fails.

To Reproduce
Steps to reproduce the behavior:

  1. Trying to parse the following query throws an exception.
SELECT *
FROM crosstab(
  'select rowid, attribute, value
   from ct
   where attribute = ''att2'' or attribute = ''att3''
   order by 1,2')
AS ct(row_name text, category_1 text, category_2 text, category_3 text);
  1. Related JSqlParser code:
    try {
            Statement selectWithCrosstab = CCJSqlParserUtil.parse(
                    "SELECT *\n" +
                    "FROM crosstab(\n" +
                    "  'select rowid, attribute, value\n" +
                    "   from ct\n" +
                    "   where attribute = ''att2'' or attribute = ''att3''\n" +
                    "   order by 1,2')\n" +
                    "AS ct(row_name text, category_1 text, category_2 text, category_3 text);"
            );
    } catch (JSQLParserException e) {
        e.printStackTrace();
    }

Expected behavior
It is possible to parse the statement.

Actual behaviour
The following exception is thrown:

net.sf.jsqlparser.JSQLParserException
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:51)
    ...
	<SNIPPED>
    ...
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "("
    at line 8, column 6.

Was expecting one of:

...

System

  • Database you are using: Postgres
  • Java Version: 11.0.3
  • JSqlParser version: 3.0
@wumpz
Copy link
Member

wumpz commented Sep 10, 2019

I think the problem is this multi name alias.

@sivaraam
Copy link
Contributor Author

I don't think ct(row_name text, category_1 text, category_2 text, category_3 text) is a multi-name alias. The syntax for the crosstab function extends the usual alias and the parser doesn't seem to be handling this.

Is it possible to make this work?

@wumpz
Copy link
Member

wumpz commented Sep 10, 2019

I will look into it. But not today.

@wumpz wumpz closed this as completed in 62a0341 Sep 20, 2019
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