pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedINSERT RETURNING
2+ messages / 2 participants
[nested] [flat]
* INSERT RETURNING
@ 2022-08-28 13:33 PG Doc comments form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Doc comments form @ 2022-08-28 13:33 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org; +Cc: goel922@gmail.com
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/14/dml-returning.html
Description:
If I execute the below query
```
CREATE TABLE users (
id serial primary key,
name varchar(255)
)
INSERT INTO users (name) VALUES ('a'), ('b'), ('c') RETURNING id
```
Is there any chance that the order of the returned ids is different from the
order of data passed
To be more clear, if the returned ids are `1, 2, 3`, is it guaranteed that
the data order is ((1, a), (2, b), (3, c)) or can it be ((1, b), (2, a), (3,
c))?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: INSERT RETURNING
@ 2022-08-28 17:16 David G. Johnston <david.g.johnston@gmail.com>
parent: PG Doc comments form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2022-08-28 17:16 UTC (permalink / raw)
To: goel922@gmail.com, Pg Docs <pgsql-docs@lists.postgresql.org>
On Sun, Aug 28, 2022 at 7:51 AM PG Doc comments form <noreply@postgresql.org>
wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/14/dml-returning.html
> Description:
>
> If I execute the below query
> ```
> CREATE TABLE users (
> id serial primary key,
> name varchar(255)
> )
> INSERT INTO users (name) VALUES ('a'), ('b'), ('c') RETURNING id
> ```
> Is there any chance that the order of the returned ids is different from
> the
> order of data passed
> To be more clear, if the returned ids are `1, 2, 3`, is it guaranteed that
> the data order is ((1, a), (2, b), (3, c)) or can it be ((1, b), (2, a),
> (3,
> c))?
>
There is no guarantee that insertion will happen in any particular order.
If you have to associate a given generated id with a given record either
the record must have it own natural key (in which case return both the
natural and surrogate keys) or you have to insert one record at a time.
David J.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2022-08-28 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-08-28 13:33 INSERT RETURNING PG Doc comments form <noreply@postgresql.org>
2022-08-28 17:16 ` David G. Johnston <david.g.johnston@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox