[BUGS] ORDER BY $1 behaves inconsistently - Mailing list pgsql-bugs

From Jordan Lewis
Subject [BUGS] ORDER BY $1 behaves inconsistently
Date
Msg-id CAALgziJijki4_scH=3LENpJ-K8WOfSQwSx_TCv4Qph6-U6XceA@mail.gmail.com
Whole thread Raw
Responses Re: [BUGS] ORDER BY $1 behaves inconsistently  (Jordan Lewis <jordanthelewis@gmail.com>)
List 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.

pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: [BUGS] BUG #14877: DISCARD ALL incorrectly resets user parameters
Next
From: Jordan Lewis
Date:
Subject: Re: [BUGS] ORDER BY $1 behaves inconsistently