> 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.