2

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 :)

1
  • Thanks for mentioning that it throws an error. It's definitely better than mere "it does not work", though it would be even more better if you posted the error message. Commented Nov 9, 2010 at 18:05

1 Answer 1

4
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
Sign up to request clarification or add additional context in comments.

2 Comments

thanks! for the fast answer. But theres one question open. Can i handle the returning data like i would handle it in a SELECT query?
@Nort: if the query is all alone, yes. You cannot use it in a join, subquery etc., however, you can wrap it into a function and use the function wherever you would use a SELECT query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.