简体   繁体   中英

Get data from the last insert query using postgres

i know there is a way how i can get the whole data from my last insert, including the auto generated fields, like id, and default content. But the problem is: How can i do this?

for eg:

INSERT INTO schema.table (col1,col2) VALUES ("rowdata1","rowdata2");

the table looks like this:

id, col1, col2, col3 (default='t')

so how can i get the value of id and col3? There's a keyword like RETURNING or so, but this throws an error :)

INSERT
INTO    schema.table (col1, col2)
VALUES  ('rowdata1', 'rowdata2')
RETURNING
        *

, or, if you only need specific columns,

INSERT
INTO    schema.table (col1, col2)
VALUES  ('rowdata1', 'rowdata2')
RETURNING
        id, col3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM