Imagine we have a test table.
CREATE TABLE test (id SERIAL, name TEXT);
Use the RETURNING statement in the INSERT statement.
INSERT INTO test (name) VALUES ('My Name') RETURNING id;
id
----
1
INSERT INTO test (name) VALUES ('My Name 1') RETURNING id;
id
----
2
More info in Postgres manual.
No comments:
Post a Comment