orientdb-docs icon indicating copy to clipboard operation
orientdb-docs copied to clipboard

Batch SQL Command Fails

Open pa-emmanuel opened this issue 5 years ago • 1 comments

I wanted to insert a record into Another_Class if Check_Class exists and I wrote the following batch SQL command but it failed with the error below. I have used the next line character (\n) around the IF as required in doc 3.0.x but it is still not working.

session.command("LET $a = (SELECT from V WHERE @class = 'Check_Class' limit 1); \n if($a.size() = 0) { \n INSERT INTO CLASS Another_Class SET name = 'test'; \n }");

xxxxxxxxxxx ERROR xxxxxxxxxxxxxxxxxxxxxx Exception in thread "main" com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error parsing query: LET $a = (SELECT from V WHERE @class = 'Check_Class' limit 1); if($a.size() = 0) { ^ INSERT INTO CLASS Another_Class SET name = 'test'; } Encountered " <IF> "if "" at line 2, column 2. Was expecting: <EOF>

pa-emmanuel avatar Aug 06 '20 07:08 pa-emmanuel

Hi @pa-emmanuel

For BATCH scripts you have to use session.execute()

Thanks

Luigi

luigidellaquila avatar Aug 06 '20 07:08 luigidellaquila