Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yry16-00032J-4y for pgsql-bugs@arkaria.postgresql.org; Tue, 12 May 2015 00:25:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yry15-0008WD-Ky for pgsql-bugs@arkaria.postgresql.org; Tue, 12 May 2015 00:25:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yry14-0008Tz-05 for pgsql-bugs@postgresql.org; Tue, 12 May 2015 00:25:46 +0000 Received: from mx-out.zmailcloud.com ([192.198.85.98] helo=mx-out-1.zmailcloud.com) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Yry10-0005nw-VR for pgsql-bugs@postgresql.org; Tue, 12 May 2015 00:25:44 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id 557AE563DB0; Mon, 11 May 2015 19:25:42 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 48C3160261; Mon, 11 May 2015 19:25:42 -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 f2W5AGE85c-s; Mon, 11 May 2015 19:25:42 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 2771A60269; Mon, 11 May 2015 19:25:42 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 18C3160264; Mon, 11 May 2015 19:25:42 -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 mZnM42d4lt4I; Mon, 11 May 2015 19:25:42 -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 A579060261; Mon, 11 May 2015 19:25:41 -0500 (CDT) Message-ID: <55514883.4000106@agliodbs.com> Date: Mon, 11 May 2015 17:25:39 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.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> 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 05:18 PM, Tom Lane wrote: > Josh Berkus writes: >> Tested On: 9.4.1, 9.3.6 >> Severity: minor >> Summary: PREPARE/EXECUTE appears to silently discard ORDER BY parameters. > >> josh=# prepare foo as select * from test order by $1; >> PREPARE > > I don't see anything wrong with this. Ordering by a provably constant > expression is a no-op, not an error. > >> What appears to be happening is that the prohibited parameter for ORDER >> BY is being silently discarded during EXECUTE. At first I thought it >> might just be doing ORDER BY 'test' in the background, but that's not it: > >> 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. josh=# select * from test order by 'test'::TEXT; test ------- test1 test9 test3 test2 (4 rows) Issue closed. -- 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