pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jordan Lewis <jordanthelewis@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: ORDER BY $1 behaves inconsistently
Date: Fri, 27 Oct 2017 14:33:12 -0400
Message-ID: <31441.1509129192@sss.pgh.pa.us> (raw)
In-Reply-To: <CAALgziKW_n9b7javO+xUMr-6VsXg9biiwCa0c3Gf91rmxqVKNQ@mail.gmail.com>
References: <CAALgziJijki4_scH=3LENpJ-K8WOfSQwSx_TCv4Qph6-U6XceA@mail.gmail.com>
	<CAALgziKW_n9b7javO+xUMr-6VsXg9biiwCa0c3Gf91rmxqVKNQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Jordan Lewis <jordanthelewis@gmail.com> writes:
> Actually, it's even worse than I thought. It seems that placeholders in
> ORDER BY clauses get entirely ignored,
> as running `EXECUTE x(1)` on the previous example with unsorted table data
> does not sort the table by the 1st
> column as expected.

"ORDER BY $1" is asking to order by some constant value (constant within
any one execution of the command, anyway), which is useless, because all
rows in the query will have the same sort key.  The planner will throw
that away as being a no-op.

"ORDER BY 1" is asking to order by the first output column.  This is
not the same thing.  You cannot get that effect with a parameter;
if you could, it would probably represent a SQL-injection hazard.

If the value of $1 were "foo" and you complained that it didn't order
by column foo, it would be exactly the same issue...

			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



view thread (4+ messages)  latest in thread

Message-ID: <31441.1509129192@sss.pgh.pa.us>
Permalink:  ../31441.1509129192@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/31441.1509129192@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jordanthelewis@gmail.com
  Subject: Re: ORDER BY $1 behaves inconsistently
  In-Reply-To: <31441.1509129192@sss.pgh.pa.us>
  References: <CAALgziJijki4_scH=3LENpJ-K8WOfSQwSx_TCv4Qph6-U6XceA@mail.gmail.com> <CAALgziKW_n9b7javO+xUMr-6VsXg9biiwCa0c3Gf91rmxqVKNQ@mail.gmail.com> <31441.1509129192@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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