From: Guillaume Cottenceau <gc@mnc.ch>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: postgresql-8.0.jar and failure of ORDER BY parameters
Date: 04 May 2005 16:30:18 +0200
Message-ID: <87ekcn9i85.fsf@meuh.mnc.ch> (raw)
In-Reply-To: <17996.1115216059@sss.pgh.pa.us>
References: <874qdjpfe5.fsf@meuh.mnc.ch>
<17996.1115216059@sss.pgh.pa.us>
Tom Lane <tgl 'at' sss.pgh.pa.us> writes:
> 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,
Yes, that's what it did. I thought this was "normal" behaviour
(even if it's cumbersome IMHO) so I have not explained it.
I'd better write for example:
actionSt.setString( 1, "surname" )
in order to sort by the value of the column named "surname", but
this has never "worked". Is it supposed to work now? I just tried
that but it didn't change the resultset, btw.
> 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.
Is there any way to give parameters to ORDER BY in a
preparedStatement then?
Thanks.
--
Guillaume Cottenceau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: gc@mnc.ch, tgl@sss.pgh.pa.us
Subject: Re: postgresql-8.0.jar and failure of ORDER BY parameters
In-Reply-To: <87ekcn9i85.fsf@meuh.mnc.ch>
References: <874qdjpfe5.fsf@meuh.mnc.ch> <17996.1115216059@sss.pgh.pa.us> <87ekcn9i85.fsf@meuh.mnc.ch>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox