1 / 8

PostgreSQL ยท SQL foundations

Insert and return in one trip

INSERT adds rows. A column list makes the mapping between values and fields visible, and RETURNING can send generated or changed values back to the client without a second query.

INSERT INTO customers (email, marketing_opt_in)
VALUES ('ada@example.com', true)
RETURNING id, created_at;

For several rows, VALUES accepts multiple parenthesized rows. The returned rows are the ones actually inserted; this is useful when identity values are assigned by the database.