Re: ORDER BY in prepared statements

Поиск
Список
Период
Сортировка
От Paul Jungwirth
Тема Re: ORDER BY in prepared statements
Дата
Msg-id CA+6hpamMqQnhJSjv0zPk=N5FR9gDN4+uVyg8Gv=dvhJSdNX-Gw@mail.gmail.com
обсуждение исходный текст
Ответ на ORDER BY in prepared statements  (Bryn Jeffries <bryn.jeffries@sydney.edu.au>)
Ответы Re: ORDER BY in prepared statements  (David G Johnston <david.g.johnston@gmail.com>)
Список pgsql-general
> In a number of places on the web I've seen it claimed that ordering can be
> set via prepared statements.
> ...
> sandbox=# PREPARE testplan(text) AS
> SELECT * FROM test ORDER BY $1;
>
> But the output is not what one would expect:
>
> sandbox=# EXECUTE testplan('gender');
> ...
> As opposed to:
> sandbox=# SELECT * FROM test ORDER BY gender;

Your prepared statement version is actually comparable to this SQL:

    SELECT * FROM test ORDER BY 'gender'

which is effectually ordering by random.

I'm not sure how to make a prepared statement that lets you name a
column when you execute it. Maybe someone else can chime in if that's
possible.

Paul


--
_________________________________
Pulchritudo splendor veritatis.


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

Предыдущее
От: Bryn Jeffries
Дата:
Сообщение: ORDER BY in prepared statements
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: ORDER BY in prepared statements