Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows
Date
Msg-id 508442CB.3050904@dunslane.net
Whole thread Raw
In response to Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows  (Andres Freund <andres@2ndquadrant.com>)
Responses Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
On 10/21/2012 01:40 PM, Andres Freund wrote:
>
> Suppose you have something like
>
> CREATE TABLE positionlog(
> id serial primary key,
> timestamp timestamptz DEFAULT NOW(),
> position geometry
> );
>
> And you want to insert multiple values in one roundtrip *and* know their ids
> in your application.
>
> INSERT INTO positionlog(position)
> VALUES
>      ('POINT(..., ...)'),
>      ('POINT(..., ...)')
> RETURNING id, timestamp, position
> ;
>
> If you want to correlate re returned ids with data in your application without
> relying on the ordering of INSERT ... VALUES... RETURNING you would need to
> sort a postgis type in the same way the server does it.


I see. Sorry, I should not have joined the thread late in the piece 
while I'm multitasking.

I guess in such a case I'd be inclined to precompute the id values and 
then supply them in the values clause. That means two round trips rather 
than one.

cheers

andrew



pgsql-hackers by date:

Previous
From: Abhijit Menon-Sen
Date:
Subject: Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows
Next
From: Andres Freund
Date:
Subject: Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows