Get the primary id of inserted line in SQL
I have a table, with autoincremented id
CREATE TABLE users (
id SERIAL NOT NULL,
name VARCHAR(30) NOT NULL,
PRIMARY KEY (id)
)
I can add a new item there with an explicit id
INSERT INTO users (id, name) VALUES (2, 'fred')
And while my id is autoincremented, I can omit it
INSERT INTO users (name) VALUES ('ed')
So, this time, I don't know the id, and I want to somehow get it.
I could do it with LAST_IDENTITY() function, but it just uses %RowID, and have no relation to the primary id
SELECT LAST_IDENTITY()
Gives 2, instead of 3
Is there any way, to make LAST_IDENTITY() match to the primary id key, or I just forget about it and use something else?
Product version: IRIS 2022.1