Re: weird behavior of ORDER BY

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "zoolus (dot)" <700671(at)gmail(dot)com>, Postgres Bug <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: weird behavior of ORDER BY
Date: 2018-04-26 13:21:13
Message-ID: 8451.1524748873@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thu, Apr 26, 2018 at 2:29 AM, zoolus . <700671(at)gmail(dot)com> wrote:
>> I think any "ORDER BY" construct can't filter result set.

> ​While a bit surprising I don't really have a problem with it. I suppose I
> would have expected that set-returning-functions in ORDER BY would be
> prohibited but absent that restriction this result is consistent with other
> behavior: if you had placed the unnest in the select-list and done "ORDER
> BY #" to reference it you would have achieved the same result.

Indeed. Consider also the case where the SRF in ORDER BY produces more
than one output per input row --- how many result rows do you expect to
get then? If you don't like reasoning about these cases, don't use a
SRF in ORDER BY.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Gopichand Gatte 2018-04-26 14:01:10 Regarding PostgreSQL
Previous Message David G. Johnston 2018-04-26 12:21:20 Re: weird behavior of ORDER BY