Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Error parsing a MS SQL Server query using UNPIVOT statement #1374

fabriziodelfranco started this conversation in General
Discussion options

Hi there!

I've been using JSqlParser for I while and I want you to know that it's working pretty well.
This is my first discussion here, so I think it's fair to thank all the contributors.

Then, I trying to parse a MS SQL Server query using UNPIVOT statement (find more here), something like this:

SELECT VendorID, Employee, Orders FROM (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 FROM pvt) p UNPIVOT (Orders FOR Employee IN (Emp1, Emp2, Emp3, Emp4, Emp5) )AS un_piv;

and I got the following error:
2021年10月13日 17:01:57,660 ERROR i.u.c.g.m.c.v.ValidationPanel [AWT-EventQueue-0] net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "un_piv" <S_IDENTIFIER> at line 30, column 4. Was expecting one of: ")" "," "APPLY" "CONNECT" "CROSS" "EXCEPT" "FOR" "FULL" "GROUP" "HAVING" "INNER" "INTERSECT" "JOIN" "LEFT" "MINUS" "NATURAL" "ORDER" "OUTER" "PIVOT" "RIGHT" "START" "STRAIGHT_JOIN" "UNION" "WHERE" "WINDOW" java.lang.IllegalArgumentException: net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "un_piv" <S_IDENTIFIER> at line 30, column 4.

So I'd created a fork, went through the code, and found that the grammar does not allow the UNPIVOT to have an alias.
I fixed it.
Now, I'd like to know if make sense to you that I create an issue and a pull request to submit my solution.

Thanks.

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

Sure. PRs are welcome. Thx for using JSqlparser. You do not need to create an additional issue. A PR will do fine. Just don't forget to give it a description or link it to this discussion.

You must be logged in to vote
1 reply
Comment options

@fabriziodelfranco I am also facing the same issue while using UNPIVOT function. Just curious if you have already submitted the pull request as this seems to be an issue.

Comment options

Greetings. Please refer to PR #1385, which has been merged.
You can use JSQLParser 4.3 Snapshot to access the new functionality.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /