Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A8E1B632DF3 for ; Sat, 1 May 2010 13:09:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 94618-03 for ; Sat, 1 May 2010 16:09:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by mail.postgresql.org (Postfix) with ESMTP id 6DE8D632C95 for ; Sat, 1 May 2010 13:09:00 -0300 (ADT) Received: from mail63.csoft.net (localhost [127.0.0.1]) by mail63.csoft.net (Postfix) with ESMTP id E584A2842A; Sat, 1 May 2010 12:08:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=csoft.net; h=date:from:to :cc:subject:in-reply-to:message-id:references:mime-version :content-type; s=sel1; bh=/qLaYgrQp2soJOsaS73Fbgqfp2s=; b=SCeiR+ W54waqarIrO8sDB5dFsGrwkaWvjKu890zaVxELSwBvS+wh0Qg4K8f6go5IYWXOQ5 SZVGCDMeY0cjZrCWnPu8vEfkWVf0BXxYf11P6aYfXnxrNS092HJObNKQ8R8zM1q1 NFtSOkEM8+sk2Hv38cA1Azmj1uUAtKNuGzmpI= Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail63.csoft.net (Postfix) with ESMTP id D63F12840C; Sat, 1 May 2010 12:08:52 -0400 (EDT) Received: by leary.csoft.net (Postfix, from userid 1112) id A9676A388; Sat, 1 May 2010 12:08:52 -0400 (EDT) Date: Sat, 1 May 2010 12:08:52 -0400 (EDT) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: "Jeenicke, Martti" cc: pgsql-jdbc@postgresql.org Subject: Re: Strange behavior after setting timestamp field to null - A bug? In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (BSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/9 X-Sequence-Number: 20493 On Mon, 8 Feb 2010, Kris Jurka wrote: > On Mon, 8 Feb 2010, Jeenicke, Martti wrote: > >> Hi there, >> >> we have noticed an odd problem/bug when working with timestamp fields in >> prepared statements. The problem arises when setting the timestamp field >> to null. The test class to reproduce the behavior produces the following >> output: >> >> 08.02.2010 16:36:20 >> 08.02.2010 16:36:20 >> 08.02.2010 16:36:20 >> 08.02.2010 17:36:20 > > I've looked into this a little bit. The problem is how the data gets typed > when it is sent to the server. When calling setTimestamp, the driver doesn't > know whether the server type that will be used will be with or without a > timezone. (The SQL Standard and the JDBC API don't match up well here.) So > it sends the data as type "unknown" and lets the server figure out how to > deal with it because it has additional type information. When calling > setNull, the driver thought it was safe to type it as timestamp with timezone > to try and help type inference because NULL values look the same with or > without timezones. This is looked OK, but you've caught the case here where > it is not. By default, the fifth execution of a PreparedStatement will > establish a more permanent execution plan that will then be re-used for later > executions. So the fifth execution in your test is a setNull case and that > is effectively establishing the types that a later execution will use as > well. So later executions fail to pass the data as "unknown" and are instead > passing it as "timestamp with tz" which does not match up with your table, so > you get the mystery drift. > > The attached patch fixes things for me in a simple test, but I'd like to look > at it a little more before I commit it. > I've committed this patch to CVS. Kris Jurka