Reputation:
I have 2 insert
queries.
In the second insert
query, I need the first insert
returned id
.
I am doing those queries as a transaction, because they depend each other.
So, is it possible to get the last insert id before committing transaction in postgres in Golang.
Upvotes: 0
Views: 1361
Reputation: 238058
Postgres supports the returning
keyword to select the inserted id
:
INSERT INTO YourTable (col1, col2) VALUES ('Value1', 'Value2') RETURNING id;
Upvotes: 1