Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YshQS-0005GS-AJ for pgsql-bugs@arkaria.postgresql.org; Thu, 14 May 2015 00:55:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YshQR-0001Oz-2X for pgsql-bugs@arkaria.postgresql.org; Thu, 14 May 2015 00:54:59 +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 1YshQE-00017b-5O for pgsql-bugs@postgresql.org; Thu, 14 May 2015 00:54:46 +0000 Received: from mx-out.zmailcloud.com ([192.198.85.98] helo=mx-out-1.zmailcloud.com) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1YshQA-0001z7-AU for pgsql-bugs@postgresql.org; Thu, 14 May 2015 00:54:45 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id D34E6564014; Wed, 13 May 2015 19:54:40 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id C206460267; Wed, 13 May 2015 19:54:40 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AKLHky7O02PE; Wed, 13 May 2015 19:54:40 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id A134760264; Wed, 13 May 2015 19:54:40 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 82F5D60267; Wed, 13 May 2015 19:54:40 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Kv_LeKs_UZYd; Wed, 13 May 2015 19:54:40 -0500 (CDT) Received: from [172.47.23.104] (50-0-190-244.dsl.dynamic.fusionbroadband.com [50.0.190.244]) by smtp-out-2.01.com (Postfix) with ESMTPSA id 0B0DD60264; Wed, 13 May 2015 19:54:39 -0500 (CDT) Message-ID: <5553F24B.8070009@agliodbs.com> Date: Wed, 13 May 2015 17:54:35 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: Prepare/Execute silently discards prohibited ORDER BY values References: <555143EC.1000808@agliodbs.com> <432.1431389890@sss.pgh.pa.us> <55514883.4000106@agliodbs.com> <5168.1431401736@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 On 05/11/2015 08:35 PM, Tom Lane wrote: >> 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. Well, the fact that: ORDER BY 'test' ... errrors, whereas ORDER BY 'test'::TEXT ... does not is a very small POLS violation. I was not the only one confused by it; pitching this on IRC, several postgres hackers and advanced users thought it was a bug. On the other hand, it's also not exactly breaking anyone's stuff once you understand what it's doing. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs