Top "Sql-returning" questions

In various SQL dialects, the RETURNING clause allows to return data from an INSERT, UPDATE or DELETE.

Can I use return value of INSERT...RETURNING in another INSERT?

Is something like this possible? INSERT INTO Table2 (val) VALUES ((INSERT INTO Table1 (name) VALUES ('a_title') RETURNING id)); like …

postgresql sql-returning
How to use RETURNING with ON CONFLICT in PostgreSQL?

I have the following UPSERT in PostgreSQL 9.5: INSERT INTO chats ("user", "contact", "name") VALUES ($1, $2, $3), ($2, $1, NULL) ON CONFLICT("user", "contact") DO …

sql postgresql upsert sql-returning
Insert data in 3 tables at a time using Postgres

I want to insert data into 3 tables with a single query. My tables looks like below: CREATE TABLE sample ( id …

sql postgresql common-table-expression sql-insert sql-returning
Variable value assignment using RETURNING clause

I try to do this, but it's a syntax error, what am I doing wrong? declare myid := insert into oameni …

sql postgresql sql-returning
Return updated row attributes on UPDATE

My query is as follow: UPDATE t1 SET t1.foreign_key = (SELECT id FROM t2 WHERE t2.col = %s ) WHERE …

sql postgresql sql-update sql-returning
PostgreSQL: Update function return boolean

Is the function below good? CREATE FUNCTION password_set(bigint, char) RETURNS boolean AS $$ UPDATE users SET password = $2 WHERE id = $1 …

postgresql sql-update boolean sql-returning
How to include excluded rows in RETURNING from INSERT ... ON CONFLICT

I've got this table (generated by Django): CREATE TABLE feeds_person ( id serial PRIMARY KEY, created timestamp with time zone …

sql django postgresql upsert sql-returning
PHP, Postgres help using RETURNING

I think I understand how PostgreSQL and RETURNING works - I've found many, many resources. If I'm catching on, it …

php postgresql sql-returning
Efficiently duplicate some rows in PostgreSQL table

I have PostgreSQL 9 database that uses auto-incrementing integers as primary keys. I want to duplicate some of the rows in …

sql postgresql sql-insert sql-returning
How to return primary key from oracle merge query

I want to return the primary key from an oracle merge query. I'm using a single statement to insert if …

oracle merge oracle10g sequence sql-returning