Error parsing a MS SQL Server query using UNPIVOT statement #1374
fabriziodelfranco
started this conversation in
General
Replies: 2 comments 1 reply
-
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. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Greetings. Please refer to PR #1385, which has been merged. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.
Beta Was this translation helpful? Give feedback.
All reactions