I have:
Insert Into(name)
Value('Anton')
How do I get the newly created id
?
I have:
Insert Into(name)
Value('Anton')
How do I get the newly created id
?
You use the RETURNING keyword
https://www.postgresql.org/docs/9.5/static/dml-returning.html
From the doc :
INSERT INTO users (firstname, lastname) VALUES ('Joe', 'Cool') RETURNING id;
Insert a single row into table distributors, returning the sequence number generated by the DEFAULT clause:
Code
INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets')
RETURNING did;
The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted. This is primarily useful for obtaining values that were supplied by defaults, such as a serial sequence number. However, any expression using the table's columns is allowed. The syntax of the RETURNING list is identical to that of the output list of SELECT.
Reference: