Re: ORDER BY $1 behaves inconsistently

From: Jordan Lewis <jordanthelewis(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: ORDER BY $1 behaves inconsistently
Date: 2017-10-27 16:53:12
Message-ID: CAALgziKW_n9b7javO+xUMr-6VsXg9biiwCa0c3Gf91rmxqVKNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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.

On Fri, Oct 27, 2017 at 12:18 PM Jordan Lewis <jordanthelewis(at)gmail(dot)com>
wrote:

> Version: 10.0
>
> As I understand it, the only valid constant datatype in an ORDER BY is
> integer. That's validated by the following test:
>
> jordan=# SELECT * FROM t ORDER BY 'foo';
> ERROR: non-integer constant in ORDER BY
> LINE 1: SELECT * FROM t ORDER BY 'foo';
>
> However, using a prepared statement, this behavior can be avoided:
>
> jordan=# PREPARE x as SELECT * FROM t ORDER BY $1;
> PREPARE
> jordan=# EXECUTE x('foo');
> c
> ---
> 1
>
> It seems to me that there is some missing type checking from ORDER BY.
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-10-27 18:33:12 Re: ORDER BY $1 behaves inconsistently
Previous Message Jordan Lewis 2017-10-27 16:18:53 ORDER BY $1 behaves inconsistently