sql-returning Questions

5

Solved

Example: create table foo( id serial, txt text ); insert into foo(txt) values ('a'),('b'),('c') returning id; Returns: id ---- 1 2 3 (3 rows) It seems that the first id in the return...
Nava asked 25/3, 2011 at 23:52

1

Solved

Here we have a certain table: CREATE TABLE mytbl ( id int PRIMARY KEY generated by default as identity, col1 int, col2 text, ... ); We need to copy part of the rows of the table and get i...
Dyer asked 20/6, 2023 at 22:24

10

Solved

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 NOTHING RETURNING id; If t...
Tachograph asked 10/1, 2016 at 17:25

3

Solved

I've already read this, this and this, but I cant make this SQL work: INSERT INTO main_phrase (description) VALUES ('Mot commun féminin pluriel animaux'); /* ERROR: */ WITH t1 AS ( SELECT id F...

2

I don't know how I can return all attributes with the RETURNING clause I want something like this: DECLARE v_user USER%ROWTYPE BEGIN INSERT INTO User VALUES (1,'Bill','QWERTY') RETURNI...
Jodi asked 22/5, 2010 at 18:23

2

Solved

I am attempting to allow insert statements with a returning clause into a view in Postgres v9.4, but am struggling with the syntax. This is how I want to call the insert statement: CREATE VIEW MyV...
Fogy asked 24/3, 2014 at 23:28

2

Solved

I am getting the users data from UUID WHERE empl_user_pub_uuid = 'e2bb39f1f28011eab66c63cb4d9c7a34'. Since I don't want to make an additional query to fetch additional user data I'm trying to sneak...

2

Solved

I try to do this, but it's a syntax error, what am I doing wrong? declare myid := insert into oameni values(default,'lol') returning id; my table: create table oameni ( id serial primary key, na...
Marucci asked 10/9, 2010 at 19:59

2

For the table B, there is a column named a_id which is the id of the table A. So a_id is the foreign key pointing to table a, but it is just a integer column and has no foreign constraint is set on...
Vinnievinnitsa asked 21/9, 2018 at 8:5

2

For a bulk insert, I have a foreign reference value. As part of the insert, I'd like to return both the reference and corresponding id's of the newly created records in order to create a mapping re...
Rafflesia asked 27/6, 2019 at 6:24

3

Solved

I execute the following query in postgres: UPDATE products SET dealer_id = CASE WHEN order_id = 7 THEN '1' WHEN order_id = 6 THEN '2' ELSE dealer_id END RETURNING id I expect to get ...
Filipe asked 24/9, 2018 at 14:5

2

Oracle supports RETURNING clause which could be very useful. For example for data: CREATE TABLE t(Id INT, Val varchar2(50)); INSERT INTO t(Id, Val) SELECT 10,'a' FROM dual UNION ALL SELECT 20,'b...
Chrysostom asked 14/9, 2018 at 19:7

6

Solved

Is something like this possible? INSERT INTO Table2 (val) VALUES ((INSERT INTO Table1 (name) VALUES ('a_title') RETURNING id)); like using the return value as value to insert a row in a second t...
Kuroshio asked 3/7, 2011 at 0:52

3

Solved

I'm using PostgreSQL 9.3. I want to duplicate some of the db records. Since I'm using an auto-increment pk id for the table, I want to get back the id mappings from the generated ids of duplicated...
Lahomalahore asked 25/3, 2015 at 13:21

2

Solved

Using Postgres 9.6, I have followed the strategy recommended in https://mcmap.net/q/28920/-return-rows-from-insert-with-on-conflict-without-needing-to-update to do an INSERT or SELECT and return th...
Spurge asked 5/10, 2017 at 13:24

2

I want to return the primary key from an oracle merge query. I'm using a single statement to insert if not exist and I don't want to use procedure or function to do so.. this is the sample query...
Cumulate asked 6/11, 2012 at 12:53

2

Solved

I've recently switched from using SQL Server to Oracle. There's some Oracle specific functions that are confusing me. The documentation at https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/ret...
Stortz asked 30/9, 2016 at 18:34

2

Solved

My query is as follow: UPDATE t1 SET t1.foreign_key = (SELECT id FROM t2 WHERE t2.col = %s ) WHERE t1.col = %s How do I return some attributes of the updated row in the table in the same query?...
Rockey asked 15/8, 2016 at 3:9

1

Solved

I've got this table (generated by Django): CREATE TABLE feeds_person ( id serial PRIMARY KEY, created timestamp with time zone NOT NULL, modified timestamp with time zone NOT NULL, name charac...
Sylphid asked 11/3, 2016 at 21:4

5

I have PostgreSQL 9 database that uses auto-incrementing integers as primary keys. I want to duplicate some of the rows in a table (based on some filter criteria), while changing one or two values,...
Lockwood asked 19/8, 2011 at 1:6

1

Solved

How do I return the value of an identity column (id) in Oracle 12c after insertion? Seems like most of the approaches out there uses sequence to get back the id of the inserted item.
Askwith asked 12/2, 2015 at 7:54

2

Solved

I want to store an update's RETURNING values into a data structure so that I can use it in a subsequent query. In this example, I'm given a list of "parent_ids", and I want to find all children wh...
Tiemroth asked 18/11, 2014 at 21:42

2

Solved

Is the function below good? CREATE FUNCTION password_set(bigint, char) RETURNS boolean AS $$ UPDATE users SET password = $2 WHERE id = $1 RETURNING TRUE; $$ LANGUAGE SQL; It returns TRUE when U...
Nape asked 14/4, 2014 at 22:29

1

Solved

I trying to perform something like CREATE TEMP TABLE tblname AS ( INSERT INTO tbl2 FROM SELECT(1,1) RETURNING a,b ); but i've got ERROR: syntax error at or near "INSERT"; Is it possible to co...
Illailladvised asked 6/3, 2014 at 8:37

4

I want to insert data into 3 tables with a single query. My tables looks like below: CREATE TABLE sample ( id bigserial PRIMARY KEY, lastname varchar(20), firstname varchar(20) ); CREATE TABLE...

© 2022 - 2024 — McMap. All rights reserved.