V 1.4.200 LAST_INSERT_ID() don't work

813 views
Skip to first unread message

Roland M.

unread,
Dec 7, 2021, 12:24:57 PM12/7/21
to H2 Database
Hello, I want to change from V1.4.199 to V1.4.200.
But unfortunately the query "SELECT LAST_INSERT_ID()" don' work anymore.
Is this a bug , or have I to use another function, and when, which one?

Best regards

Evgenij Ryazanov

unread,
Dec 7, 2021, 7:33:17 PM12/7/21
to H2 Database
Hello.

This function is a part of MSSQLServer compatibility mode and is not available in other modes anymore.

For identity columns In Regular mode you need to ask an insert or merge operation about the inserted data.

With JDBC you can use Statement.getGeneratedKeys() if Statement.RETURN_GENERATED_KEYS, column names, or column indexes were specified earlier.

With SQL only you can use standard data change delta tables:

SELECT ID FROM FINAL TABLE (INSERT INTO TEST (A, B) VALUES (1, 2))

If you have separate sequences, you can use non-standard and non-portable
VALUES CURRENT VALUE FOR sequenceName
but normally you should only use standard NEXT VALUE FOR sequenceName when new generated value is needed.

Roland M.

unread,
Dec 10, 2021, 12:43:45 AM12/10/21
to H2 Database
Ah,
ok. Thank you very much for the detailed answer!

Reply all
Reply to author
Forward
0 new messages