Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, "Abhijit Menon-Sen" <ams(at)2ndquadrant(dot)com>, Christopher Browne <cbbrowne(at)gmail(dot)com>
Subject: Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows
Date: 2012-10-21 16:36:29
Message-ID: 201210211836.33167.andres@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sunday, October 21, 2012 06:30:14 PM Andrew Dunstan wrote:
> On 10/21/2012 12:20 PM, Abhijit Menon-Sen wrote:
> > At 2012-10-21 11:49:26 -0400, cbbrowne(at)gmail(dot)com wrote:
> >> If there is a natural sequence (e.g. - a value assigned by nextval()),
> >> that offers a natural place to apply the usual order-imposing ORDER BY
> >> that we are expected to use elsewhere.
> >
> > Note: "INSERT … RETURNING" doesn't accept an ORDER BY clause.
>
> No, but you can wrap the INSERT .. RETURNING in a CTE and order that.

Personally I find that a not very practical suggestion. It means you need the
ability to sort the data equivalently on the clientside which isn't always
easy if you consider platform/locale and whatever differences.

Suggesting nextval() doesn't strike me as very practical either because it
means that you either need a separate roundtrip to the server to get a bunch
of new ids which you then can assign to the to-be-inserted rows or you need
the ability to match the returned rows to the inserted rows somehow. Thats not
always easy.

Andres
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message P. Christeas 2012-10-21 16:40:33 Re: Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows
Previous Message Andrew Dunstan 2012-10-21 16:30:14 Re: Re: [PATCH] Enforce that INSERT...RETURNING preserves the order of multi rows