The RETURNING Clause
An INSERT statement may optionally include a RETURNING clause to return values from the inserted rows.The clause, if present, need not contain all columns referenced in the insert statement and may also contain other columns or expressions.The returned values reflect any changes that may have been made in BEFORE INSERT triggers.
The user executing the statement needs to have SELECT privileges on the columns specified in the RETURNING clause.
The syntax of the returning_list is similar to the column list of a SELECT clause.It is possible to reference all columns using * or table_name.*.
The optional INTO sub-clause is only valid in PSQL.
|
Note
|
Caveats for updatable views
The values reported by |
|
Important
|
Multiple
INSERTsIn DSQL, an In PSQL, if the |
INSERT INTO Scholars (firstname, lastname, address,
phone, email)
VALUES ('Henry', 'Higgins', '27A Wimpole Street',
'3231212', NULL)
RETURNING lastname, fullname, id;
INSERT INTO Scholars (firstname, lastname, address,
phone, email)
VALUES (
'Henry', 'Higgins', '27A Wimpole Street',
'3231212', NULL)
RETURNING *;
INSERT INTO Dumbbells (firstname, lastname, iq)
SELECT fname, lname, iq
FROM Friends
ORDER BY iq ROWS 1
RETURNING id, firstname, iq
INTO :id, :fname, :iq;
|
Note
|
|