Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id B9D549F9945 for ; Fri, 13 Oct 2006 04:53:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 23030-07-2 for ; Fri, 13 Oct 2006 07:52:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mnc.ch (62-2-77-205.static.cablecom.ch [62.2.77.205]) by postgresql.org (Postfix) with ESMTP id 58F509F946A for ; Fri, 13 Oct 2006 04:49:26 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.mnc.ch (Postfix) with ESMTP id E4C42A82B7 for ; Fri, 13 Oct 2006 09:53:49 +0200 (CEST) Received: from mail.mnc.ch ([127.0.0.1]) by localhost (mail.test.lan [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 08301-06 for ; Fri, 13 Oct 2006 09:53:47 +0200 (CEST) Received: from meuh.mnc.lan (62-2-77-204.static.cablecom.ch [62.2.77.204]) by mail.mnc.ch (Postfix) with ESMTP id D1B14A82B2 for ; Fri, 13 Oct 2006 09:53:47 +0200 (CEST) Received: by meuh.mnc.lan (Postfix, from userid 1000) id F096A1836FB; Fri, 13 Oct 2006 09:48:40 +0200 (CEST) To: pgsql-jdbc@postgresql.org Subject: 'now' is sometimes not now - but current_timestamp is X-Hashcash: 1:20:061013:pgsql-jdbc@postgresql.org::P83oedlOjsFu3Ba7:00000000000000000000000000000000000039ng From: Guillaume Cottenceau Date: 13 Oct 2006 09:48:40 +0200 Message-ID: <87pscwk65j.fsf@meuh.mnc.lan> Lines: 52 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: amavisd-new at mnc.ch X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/82 X-Sequence-Number: 15965 Hi, I update a row's TIMESTAMP WITH TIME ZONE column value with: ... SET = 'now'::TIMESTAMP WITH TIME ZONE ... Initially, I was hesitating with CURRENT_TIMESTAMP, but in a table description, a column with a default value of 'now' or CURRENT_TIMESTAMP will both be printed "not null default ('now'::text)::timestamp(6) with time zone" so I assumed the correct way of writing it was 'now' and then to cast to a timestamp with/without time zone. However, I have seen that some entries in the table get wrongly updated to the same timestamp in the past. Just like if the updates after one of them were then using always the same timestamp as this one instead of 'now'. I use prepared statements, so I suppose there might be something wrong there with optimization or the fact that the query is sent to the server. I use prepared statements with ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY and a prepare threshold of 5. I have experimented with CURRENT_TIMESTAMP instead of 'now', and it "fixes" the problem. Also, and now it's getting kinda funny, using ('now'::text)::TIMESTAMP WITH TIME ZONE also "fixes" the problem. So only the 'now'::TIMESTAMP WITH TIME ZONE form exhausts the problem. So I was curious about it, a feature, a bug, a misunderstanding from my side? In the documentation, I could find that "String literals specifying time-varying date/time values, such as 'now' or 'today' will no longer work as expected in column default expressions" in the 7.4 release notes, but that's only talking about column default expressions right? [1] seems to confirm (in the form "TIMESTAMP 'now'") that the problem is limited to column default values. I am unsure if "not null default ('now'::text)::timestamp(6) with time zone" in the table description is not a bit misleading then, since CURRENT_TIMESTAMP or now() should be rather used - or maybe 'now' should be deprecated completely? Using postgresql-8.1-407.jdbc3.jar over java 1.4.2 connecting to a 7.4 database. Ref: [1] http://www.postgresql.org/docs/{7.4,8.1}/interactive/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT -- Guillaume Cottenceau Create your personal SMS or WAP Service - visit http://mobilefriends.ch/