pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Fwd: weird behavior of ORDER BY
3+ messages / 3 participants
[nested] [flat]

* Fwd: weird behavior of ORDER BY
@ 2018-04-26 09:29 zoolus . <700671@gmail.com>
  2018-04-26 12:21 ` Re: weird behavior of ORDER BY David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: zoolus . @ 2018-04-26 09:29 UTC (permalink / raw)
  To: pgsql-bugs

pgsql-bugs@postgresql.org


Hello, friends!

This statement returns nothing:

WITH x AS (VALUES (1))
SELECT * FROM x
ORDER BY unnest(NULL :: INT [])
;

--0 rows retrieved
--PostgreSQL 9.6.1, compiled by Visual C++ build 1800, 64-bit
--PostgreSQL 10.3, compiled by Visual C++ build 1800, 64-bit

I think any "ORDER BY" construct can't filter result set.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: weird behavior of ORDER BY
  2018-04-26 09:29 Fwd: weird behavior of ORDER BY zoolus . <700671@gmail.com>
@ 2018-04-26 12:21 ` David G. Johnston <david.g.johnston@gmail.com>
  2018-04-26 13:21   ` Re: weird behavior of ORDER BY Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2018-04-26 12:21 UTC (permalink / raw)
  To: zoolus . <700671@gmail.com>; +Cc: pgsql-bugs

On Thu, Apr 26, 2018 at 2:29 AM, zoolus . <700671@gmail.com> wrote:

> pgsql-bugs@postgresql.org
>
>
> Hello, friends!
>
> This statement returns nothing:
>
> WITH x AS (VALUES (1))
> SELECT * FROM x
> ORDER BY unnest(NULL :: INT [])
> ;
>
> --0 rows retrieved
> --PostgreSQL 9.6.1, compiled by Visual C++ build 1800, 64-bit
> --PostgreSQL 10.3, compiled by Visual C++ build 1800, 64-bit
>
> 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.

One of the hackers would need to provide insight as to how reasonable
"fixing" this behavior would be (and whether the standard has anything to
say on the topic) - otherwise a quick documentation update would suffice
for me personally.

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: weird behavior of ORDER BY
  2018-04-26 09:29 Fwd: weird behavior of ORDER BY zoolus . <700671@gmail.com>
  2018-04-26 12:21 ` Re: weird behavior of ORDER BY David G. Johnston <david.g.johnston@gmail.com>
@ 2018-04-26 13:21   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2018-04-26 13:21 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: zoolus . <700671@gmail.com>; pgsql-bugs

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thu, Apr 26, 2018 at 2:29 AM, zoolus . <700671@gmail.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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-04-26 13:21 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 09:29 Fwd: weird behavior of ORDER BY zoolus . <700671@gmail.com>
2018-04-26 12:21 ` David G. Johnston <david.g.johnston@gmail.com>
2018-04-26 13:21   ` 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