ORDER BY $1 behaves inconsistently

From: Jordan Lewis <jordanthelewis(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: ORDER BY $1 behaves inconsistently
Date: 2017-10-27 16:18:53
Message-ID: CAALgziJijki4_scH=3LENpJ-K8WOfSQwSx_TCv4Qph6-U6XceA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jordan Lewis 2017-10-27 16:53:12 Re: ORDER BY $1 behaves inconsistently
Previous Message David G. Johnston 2017-10-27 14:26:39 Re: BUG #14877: DISCARD ALL incorrectly resets user parameters