Re: Behavior of subselects in target lists and order by

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Behavior of subselects in target lists and order by
Date: 2012-02-25 09:07:55
Message-ID: jia8db$qas$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 2012-02-24, amit sehas <cun23(at)yahoo(dot)com> wrote:
> If we have a query of the form:
>
> Select *, (Select * FROM T2 WHERE p2 = T1.p1) FROM T1 ORDER BY 1 WHERE p3 = 75
>
> In the above query there is a subselect in the target list and the
> ORDERBY has an ordinal number which indicates order by column 1. Does
> this mean that the above query will return all results from T1 that
> match p3 =75 and all results from T2 that match p2 = T1.p1 for every
> match on T1 and order them all by the first column of T1 and T2 ?
>
> basically i am trying to determine if the order by clause has effect
> only on the tuples of the outer select or both the outer and inner
> select. Or the results returned by the inner select are treated as if
> they are part of a single tuple which includes the tuple from table T1 ?
>
> Is this an implementation specific behaviour or it conforms to the SQL standard ...?

with the exception of queries using "distinct on(...)" order by will
only effect the order in which the results are presented. Where
distinct on is used it will also effect which distinct subset set of
rows are presented.

Distinct on is outside the standard, otherwise postgres follows the
standard,

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2012-02-25 09:47:21 Re: How to typecast an integer into a timestamp?
Previous Message Frank Church 2012-02-25 08:28:26 What effect does destroying database related threads have on system resources?

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergey Burladyan 2012-02-25 10:29:36 Re: Patch for BUG #6480, psql incorrect indent for inherited tables names with UTF-8 NLS
Previous Message Noah Misch 2012-02-25 05:57:17 Re: psql COPY vs. ON_ERROR_ROLLBACK, multi-command strings