Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ys0z0-0002pl-4a for pgsql-bugs@arkaria.postgresql.org; Tue, 12 May 2015 03:35:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ys0yy-0008Ts-I2 for pgsql-bugs@arkaria.postgresql.org; Tue, 12 May 2015 03:35:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Ys0yw-0008Tj-Kw for pgsql-bugs@postgresql.org; Tue, 12 May 2015 03:35:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Ys0yo-00005r-U3 for pgsql-bugs@postgresql.org; Tue, 12 May 2015 03:35:46 +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 t4C3Za7H005169; Mon, 11 May 2015 23:35:36 -0400 From: Tom Lane To: Josh Berkus cc: pgsql-bugs@postgresql.org Subject: Re: Prepare/Execute silently discards prohibited ORDER BY values In-reply-to: <55514883.4000106@agliodbs.com> References: <555143EC.1000808@agliodbs.com> <432.1431389890@sss.pgh.pa.us> <55514883.4000106@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Mon, 11 May 2015 17:25:39 -0700" Date: Mon, 11 May 2015 23:35:36 -0400 Message-ID: <5168.1431401736@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Josh Berkus writes: > On 05/11/2015 05:18 PM, Tom Lane wrote: >> Josh Berkus writes: >>> josh=# select * from test order by 'test'; >>> ERROR: non-integer constant in ORDER BY >> This error is purely a syntactic restriction, not a semantic one. >> There's nothing that will stop you from ordering by, say, "cos(0)"; >> and the planner will throw that away too. > Ah, ok. The problem is that in the SELECT case, 'test' isn't typed, so > the parser is trying to evaluate it and fails? That makes sense. Well, not quite. The core problem is that SQL92 said that "ORDER BY n" (where "n" could only be an integer constant) means "order by the N'th output column" ... and then SQL99 forgot about that altogether, and defined the entirely more sensible rule that ORDER BY items are just expressions that have their face value. We try to support both of those cases, both for backwards compatibility and because ORDER BY n (also GROUP BY n) is such a damn handy abbreviation so much of the time. Somewhere along the line we decided that "ORDER BY non-integer-constant" was too close to the boundary line between those two interpretations, so it would be better to reject it and make you use a less ambiguous syntax. I'm too lazy to go digging in the archives for that discussion (it was quite a few years back, though). But that's why you're seeing a syntax failure for "ORDER BY 'test'". We could certainly make that case do something else if we wanted ... but I'm not sure it'd be an improvement. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs