INSERT ... RETURNING
Return columns from rows affected by an INSERT statement.
returning clause insert returning output clause insert output
insert returning output
| Database | Status | Syntax Family | Min Version |
|---|---|---|---|
| PostgreSQL | full | returning | 8.2 |
| MySQL | none | - | - |
| MariaDB | full | returning | 10.5 |
| Oracle | full | returning-into | - |
| SQL Server | full | output | - |
| SQLite | full | returning | 3.35.0 |
| Redshift | none | - | - |
| DB2 | full | select-from-insert | - |
| Snowflake | none | - | - |
| BigQuery | none | - | - |
Compare Databases
Database Details
PostgreSQL
full
INSERT INTO users (name, email)
VALUES ('Alice', 'alice@example.com')
RETURNING id, name;- Works with INSERT, UPDATE, and DELETE.
- Can return any column or expression, including generated values.
Docs: INSERT ... RETURNING
MySQL
none
- No RETURNING clause.
- Use LAST_INSERT_ID() to retrieve the auto-increment value after INSERT.
Docs: INSERT
MariaDB
full
INSERT INTO users (name, email)
VALUES ('Alice', 'alice@example.com')
RETURNING id, name;- INSERT ... RETURNING supported since MariaDB 10.5.
- DELETE ... RETURNING supported since MariaDB 10.0.5.
- UPDATE ... RETURNING is not supported in current MariaDB releases, but that does not affect INSERT ... RETURNING support.
Oracle
full
INSERT INTO users (name, email)
VALUES ('Alice', 'alice@example.com')
RETURNING id INTO v_id;- Uses RETURNING ... INTO, which requires PL/SQL bind variables.
- Cannot be used directly in plain SQL; requires a PL/SQL block or client binding.
Docs: RETURNING INTO Clause
SQL Server
full
INSERT INTO users (name, email)
OUTPUT INSERTED.id, INSERTED.name
VALUES ('Alice', 'alice@example.com');- Uses OUTPUT clause with INSERTED pseudo-table.
- Can also output into a table variable with OUTPUT INTO.
Docs: OUTPUT Clause
SQLite
full
INSERT INTO users (name, email)
VALUES ('Alice', 'alice@example.com')
RETURNING id, name;- Added in SQLite 3.35.0 (2021-03-12).
- Works with INSERT, UPDATE, and DELETE.
Docs: RETURNING
Redshift
none
- Redshift does not support the RETURNING clause on INSERT, UPDATE, or DELETE statements.
- Use a SELECT before/after the operation, or rely on IDENTITY column values via LAST_INSERT_ID workarounds.
Docs: INSERT
DB2
full
SELECT id, name
FROM FINAL TABLE (
INSERT INTO users (name, email)
VALUES ('Alice', 'alice@example.com')
);- Uses SELECT FROM FINAL TABLE (INSERT ...) syntax.
- FINAL TABLE returns the post-trigger state of the rows.
Docs: SELECT from INSERT
Snowflake
none
- Snowflake does not support RETURNING.
- Use a separate SELECT with the same key conditions to retrieve inserted values, or use sequences/UUID functions to generate keys before insertion.
Docs: INSERT
BigQuery
none
- BigQuery does not support a RETURNING clause.
- Use GENERATE_UUID() to pre-generate keys in application code before inserting, or query the table after the INSERT.
Docs: BigQuery DML syntax