Re: [BUGS] ORDER BY $1 behaves inconsistently

Поиск
Список
Период
Сортировка
От Jordan Lewis
Тема Re: [BUGS] ORDER BY $1 behaves inconsistently
Дата
Msg-id CAALgziKW_n9b7javO+xUMr-6VsXg9biiwCa0c3Gf91rmxqVKNQ@mail.gmail.com
обсуждение исходный текст
Ответ на [BUGS] ORDER BY $1 behaves inconsistently  (Jordan Lewis <jordanthelewis@gmail.com>)
Ответы Re: [BUGS] ORDER BY $1 behaves inconsistently
Список 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@gmail.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.

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Jordan Lewis
Дата:
Сообщение: [BUGS] ORDER BY $1 behaves inconsistently
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [BUGS] ORDER BY $1 behaves inconsistently