pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedordering of selected rows from an ordered subselect
3+ messages / 3 participants
[nested] [flat]
* ordering of selected rows from an ordered subselect
@ 2007-02-17 09:32 Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Rajesh Kumar Mallah @ 2007-02-17 09:32 UTC (permalink / raw)
To: pgsql-sql
Hi,
we know that rows in a table are not stored in any particular order
and explicit order by clause is required to get data in any particular
order.
but does it apply to select queries from ordered subselects also ?
eg
select id , name , expensive_func(name) from
( select id , name from tab order by c1 desc limit 15) as foo ;
is it guaranteed that the final result is order by c1 ?
Regds
mallah.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ordering of selected rows from an ordered subselect
@ 2007-02-17 15:24 Andrew Sullivan <ajs@crankycanuck.ca>
parent: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Sullivan @ 2007-02-17 15:24 UTC (permalink / raw)
To: pgsql-sql
On Sat, Feb 17, 2007 at 03:02:06PM +0530, Rajesh Kumar Mallah wrote:
>
> select id , name , expensive_func(name) from
> ( select id , name from tab order by c1 desc limit 15) as foo ;
>
> is it guaranteed that the final result is order by c1 ?
No, because expensive_func(name) might do something that alters it,
no? All things considered, it's a pretty good _bet_ it will be
ordered as you wish, though.
A
--
Andrew Sullivan | ajs@crankycanuck.ca
The whole tendency of modern prose is away from concreteness.
--George Orwell
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ordering of selected rows from an ordered subselect
@ 2007-02-17 16:31 Tom Lane <tgl@sss.pgh.pa.us>
parent: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2007-02-17 16:31 UTC (permalink / raw)
To: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>; +Cc: pgsql-sql
"Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
> select id , name , expensive_func(name) from
> ( select id , name from tab order by c1 desc limit 15) as foo ;
> is it guaranteed that the final result is order by c1 ?
The sub-select's output will be emitted in the specified order. What
happens after that depends on the outer query, but if you don't have any
joining or grouping then it's a reasonably safe bet that the final
output will be in the same order.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-02-17 16:31 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-17 09:32 ordering of selected rows from an ordered subselect Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
2007-02-17 15:24 ` Andrew Sullivan <ajs@crankycanuck.ca>
2007-02-17 16:31 ` Tom Lane <tgl@sss.pgh.pa.us>
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