ParseException when MERGE is used in a statement #1862
-
Hello everyone, I'm trying to parse a statement to get the target and source tables and save them into a file.
It works fine on SQL Server but when I try to parse it with jsqlparser with the function CCJSqlParserUtil.parse(statement) it throws a net.sf.jsqlparser.parser.ParseException, that says:
Why does jsqlparser expect an INTO after the MERGE keyword? My SQL code works fine on SQL Server. Thank you in advance for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Greetings, your syntax is not SQL:2016 compliant. |
Beta Was this translation helpful? Give feedback.
-
You SQL:2016 compliant MERGE INTO tab_roomlocation AS troom USING wmachine ON ( troom.projcode = wmachine.projcode AND troom.plantcode = wmachine.plantcode AND troom.buildingcode = wmachine.buildingcode AND troom.floorcode = wmachine.floorcode AND troom.room = wmachine.room ) WHEN NOT MATCHED THEN INSERT ( projcode , plantcode , buildingcode , floorcode , room ) VALUES ( wmachine.projcode , wmachine.plantcode , wmachine.buildingcode , wmachine.floorcode , wmachine.room ) ; We do not support the |
Beta Was this translation helpful? Give feedback.
-
Hello, Thank you for your answers and the code example. I tested the code with the link you sent me and it shows me an error, as you said. I will configure my program to accept the Merge statements with the syntax you showed me. Have a nice day. |
Beta Was this translation helpful? Give feedback.
-
Greetings! I have added support for WITH wmachine AS ( SELECT DISTINCT projcode , plantcode , buildingcode , floorcode , room FROM tab_machinelocation WHERE Trim( Room ) <> '' AND Trim( Room ) <> '-' ) MERGE INTO tab_roomlocation AS troom USING wmachine ON ( troom.projcode = wmachine.projcode AND troom.plantcode = wmachine.plantcode AND troom.buildingcode = wmachine.buildingcode AND troom.floorcode = wmachine.floorcode AND troom.room = wmachine.room ) WHEN NOT MATCHED /* BY TARGET */ THEN INSERT ( projcode , plantcode , buildingcode , floorcode , room ) VALUES ( wmachine.projcode , wmachine.plantcode , wmachine.buildingcode , wmachine.floorcode , wmachine.room ) OUTPUT Getdate() AS timeaction , $action AS action , inserted.projcode , inserted.plantcode , inserted.buildingcode , inserted.floorcode , inserted.room INTO tab_mergeactions_roomlocation ; |
Beta Was this translation helpful? Give feedback.
Greetings!
I have added support for
WITH ...
and theOutput
Clause.You can test your statement online here.