Re: 'order by' in an insert into command

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>, pgsql general list <pgsql-general(at)postgresql(dot)org>
Subject: Re: 'order by' in an insert into command
Date: 2004-09-08 17:33:17
Message-ID: 21772.1094664797@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Richard Huxton <dev(at)archonet(dot)com> writes:
> In your example, I would expect the nextval() to be called during the
> "fetch", before the ordering. You could probably do something like:

> INSERT INTO pending_tnmt_sec
> SELECT foo.*, nextval('sec_seq') FROM
> (
> SELECT tseceventid, ...
> ORDER BY tsecrtddt,tseceventid,tsecsecno
> ) AS foo
> ;

> I'm not sure whether the SQL standard requires the ORDER BY to be
> processed in the sub-select. From a relational viewpoint, I suppose you
> could argue that ordering is strictly an output feature.

I believe the SQL standard disallows this entirely, precisely because it
considers ordering to be strictly an output feature. Postgres will take
it though (in recent releases), and should produce the results Mike wants.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Thomas 2004-09-08 17:37:25 Re: Need Help in interface..
Previous Message Oliver Elphick 2004-09-08 17:30:50 Re: Heritage