Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1CC2B9FB39F for ; Mon, 18 Jun 2007 09:51:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 38476-06 for ; Mon, 18 Jun 2007 09:50:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from beaver.fastcrypt.com (beaver.fastcrypt.com [64.7.141.17]) by postgresql.org (Postfix) with ESMTP id 458069FA5F7 for ; Mon, 18 Jun 2007 09:51:06 -0300 (ADT) Received: from [192.168.1.14] (dcdsl.ebox.com [64.7.143.116]) by beaver.fastcrypt.com (Postfix) with ESMTP id 6C8A4158068D; Mon, 18 Jun 2007 09:02:14 -0400 (EDT) In-Reply-To: <094DD6D8-B500-479F-B730-0BFCC256A5DE@internode.on.net> References: <094DD6D8-B500-479F-B730-0BFCC256A5DE@internode.on.net> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <3C057C29-294D-40DF-AB97-A5400BF2E31D@fastcrypt.com> Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: Literal vs parameterized 'timestamp with time zone' value Date: Mon, 18 Jun 2007 08:51:24 -0400 To: Christopher Hunt X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/57 X-Sequence-Number: 17119 On 18-Jun-07, at 8:34 AM, Christopher Hunt wrote: > Hi there, > > This one has been baffling me for several hours so I hope that the > list can help. > > I'm having an awful difficulty specifying a parameter in a select > where clause of a prepared statement. > > Please consider this schema: > > Table "public.moving_object_status" > Column | Type | Modifiers > --------------+-----------------------------+----------- > validtime | timestamp(2) with time zone | not null > Indexes: > "moving_object_status_validtime" btree (validtime) > > (other columns removed for brevity). > > If I create the following prepared statement: > > PreparedStatement sqlStatement = > sqlConnection.prepareStatement("select validtime from > moving_object_status where validtime < '2005-06-08T20:05:45.825+0'"); > > then 1 row is returned as I would expect given my dataset. > > However if I use a parameter: > > PreparedStatement sqlStatement = > sqlConnection.prepareStatement("select validtime from > moving_object_status where validtime < ?"); > int columnIndex = 1; > sqlStatement.setString(columnIndex++, "2005-06-08T20:05:45.825+0"); > I think you need to use setTimestamp here... I'm actually surprised it doesn't throw an exception. > No rows are returned. > > Can anyone explain the difference in results given a literal value > and a parameterised value in this context? > > Kind regards, > Christopher > > ---------------------------(end of > broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that > your > message can get through to the mailing list cleanly