X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3B51C54695 for ; Wed, 4 May 2005 11:30:30 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66097-05 for ; Wed, 4 May 2005 14:30:23 +0000 (GMT) Received: from mnc.ch (www.mnc.ch [212.23.250.43]) by svr1.postgresql.org (Postfix) with ESMTP id 9D92F52A57 for ; Wed, 4 May 2005 11:30:19 -0300 (ADT) Received: (qmail 10110 invoked from network); 4 May 2005 16:30:22 +0200 Received: from 62-2-77-204.business.cablecom.ch (HELO meuh.mnc.ch) (62.2.77.204) by www.mnc.ch with SMTP; 4 May 2005 16:30:22 +0200 Received: by meuh.mnc.ch (Postfix, from userid 1000) id 59E5123EF18; Wed, 4 May 2005 16:30:18 +0200 (CEST) To: Tom Lane Cc: pgsql-jdbc@postgresql.org Subject: Re: postgresql-8.0.jar and failure of ORDER BY parameters References: <874qdjpfe5.fsf@meuh.mnc.ch> <17996.1115216059@sss.pgh.pa.us> From: Guillaume Cottenceau Date: 04 May 2005 16:30:18 +0200 In-Reply-To: <17996.1115216059@sss.pgh.pa.us> Message-ID: <87ekcn9i85.fsf@meuh.mnc.ch> Lines: 42 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.051 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200505/17 X-Sequence-Number: 12848 Tom Lane writes: > Guillaume Cottenceau 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