knowledge/INSERT ... RETURNING.md
Marco D'Agostini 95782bbca6 Added missing tag header to some documents
Added `english` / `spanish` tags and added `english` tag to template
2021-02-24 17:10:55 +01:00

611 B

tags
database, potsgresql, sql, english

INSERT ... RETURNING

You can return any information about any inserted element in the INSERT statement by using the RETURNING ... clause

Example

INSERT INTO roles (name)
VALUES ('master')
RETURNING role_id

So after RETURNING you choose all the columns you want to get

Very useful along The WITH statement to chain a bunch of insertions atomically without using transactions


What led to learning this