Search code examples
nexusdb

NexusDB declare and set table result in a variable and select it


In NexusDB I'm trying to create add a query result in a variable, then update the selected items and later select the variable

START TRANSACTION;
    set result = (SELECT * FROM "some_table" where synced = false);
    UPDATE some_table set synced = true where synced = false;
    select result;
COMMIT;

NexusDB: Query78696906: Query execution failed: Error in statement: Unable to resolve the identifier "result" at line 4, pos 12

Answer:

 SELECT * INTO #tmp from some_table where synced is null;
 UPDATE some_table set synced = true where synced is null;
 select * #tmp;

Solution

  • "select result" is a syntax error. NexusDB expects you to select from something; in this case, you can use the built-in #dummy table that is there for this exact purpose. So:

    SELECT result FROM #dummy