Try

INSERT INTO Questions VALUES (
    ?,
    ?,
    (WITH S(NAME) AS (VALUES ?)
        SELECT id FROM QuestionTypes JOIN S ON QuestionTypes.name = S.NAME
        UNION SELECT id FROM FINAL TABLE (
            MERGE INTO QuestionTypes T USING S ON T.name = S.NAME WHEN NOT 
MATCHED THEN INSERT (name) VALUES (S.NAME)
        )
    ),
    ? FORMAT JSON,
    ? FORMAT JSON
);

You need a recent version of H2 for such command, old versions don't 
support this syntax.

Don't forget to create a constraint to ensure data consistency and to speed 
up this command:
ALTER TABLE QuestionTypes ADD UNIQUE(name);


-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/6c33c253-97f9-4043-92d2-e92ecc5b1fc6%40googlegroups.com.

Reply via email to