-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Error parsing a MS SQL Server query using UNPIVOT statement #1374
-
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
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.
All reactions
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
Greetings. Please refer to PR #1385, which has been merged.
You can use JSQLParser 4.3 Snapshot to access the new functionality.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1