Re: postgresql-8.0.jar and failure of ORDER BY parameters - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: postgresql-8.0.jar and failure of ORDER BY parameters
Date
Msg-id 17996.1115216059@sss.pgh.pa.us
Whole thread Raw
In response to postgresql-8.0.jar and failure of ORDER BY parameters  (Guillaume Cottenceau <gc@mnc.ch>)
Responses Re: postgresql-8.0.jar and failure of ORDER BY parameters
List pgsql-jdbc
Guillaume Cottenceau <gc@mnc.ch> writes:
>         SELECT .... ORDER BY ?, ?

>     actionSt.setInt( 1, 4 );
>     actionSt.setInt( 2, 5 );

This would appear to be asking for a sort by two constant values,
which of course is not going to order the data usefully at all
--- all the rows will have the same sort keys.

I suppose that it behaved differently in older versions of the JDBC
driver that didn't implement real server-side prepared statements.
If the parameters are substituted textually before the server sees
the command, then you have "ORDER BY 4,5" which is interpreted according
to the old SQL92 syntax --- ie, sort by fourth and fifth columns of the
output.  But anything beyond a simple integer literal --- in particular,
a parameter symbol --- is treated as an expression value per SQL99.

So no, you can't do it like that.  The fact that it happened to "work"
before was an artifact of the implementation.

            regards, tom lane

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Connectivity of postgreSQL database to a JSP page
Next
From: Guillaume Cottenceau
Date:
Subject: Re: postgresql-8.0.jar and failure of ORDER BY parameters