Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBgpy-0006Xs-N9 for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Apr 2018 13:21:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fBgpv-0006qb-Rg for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Apr 2018 13:21:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBgpv-0006q5-HU for pgsql-bugs@lists.postgresql.org; Thu, 26 Apr 2018 13:21:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBgpn-0002Pb-Vl for pgsql-bugs@postgresql.org; Thu, 26 Apr 2018 13:21:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w3QDLDM3008452; Thu, 26 Apr 2018 09:21:13 -0400 From: Tom Lane To: "David G. Johnston" cc: "zoolus ." <700671@gmail.com>, Postgres Bug Subject: Re: weird behavior of ORDER BY In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Thu, 26 Apr 2018 05:21:20 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <8450.1524748873.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 26 Apr 2018 09:21:13 -0400 Message-ID: <8451.1524748873@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" 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. > =E2=80=8BWhile 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 ot= her > behavior: if you had placed the unnest in the select-list and done "ORDE= R > 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