Negative result with (now()-previously_inserted_timestamp)

From: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
To: PGSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Negative result with (now()-previously_inserted_timestamp)
Date: 2010-07-07 04:07:38
Message-ID: AANLkTilzZ7oxzF_uUDecIDDLkInz6v4X8K5K_pRzsh3k@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I have an IRC logger storing its data in a Postgres 8.3.3. The table in
question has the interesting column declared as:

time timestamp with time zone default now()

The logger uses a prepared statement to insert data, and does not mention
this column in the INSERT statement, hence the assumption that default
clause is being used.

I ran the following query, and got an unexpected negative value. Does this
imply that SELECT-transaction was able to see a row created by
INSERT-transaction which started after the SELECT-transaction?

postgres=> select channel, min( now()-time ) from irclog group by channel
order by 2 asc;
channel | min
--------------+-------------------------
#archlinux | -00:00:00.11686
##C | 00:00:00.09718
#debian | 00:00:00.482193
##linux | 00:00:01.172365
...
# | 36 days 14:01:17.395093
(21 rows)

(Note: the '#' row can serve as a diagnosis starting point since that
channel group has never been inserted into since the incident)

I scoured the release notes 8.3.4 to 8.3.11 for any relevant fixes and found
only this one:

http://www.postgresql.org/docs/8.3/static/release-8-3-5.html
Fix improper display of fractional seconds in interval values when using a
non-ISO datestyle in an --enable-integer-datetimes build (Ron Mayer)

But I don't think this applies to this bug report as I am using ISO
datestyle.

postgres=> show DateStyle;
DateStyle
-----------
ISO, MDY
(1 row)

Regards,
--
gurjeet.singh
@ EnterpriseDB - The Enterprise Postgres Company
http://www.EnterpriseDB.com

singh(dot)gurjeet(at){ gmail | yahoo }.com
Twitter/Skype: singh_gurjeet

Mail sent from my BlackLaptop device

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2010-07-07 04:18:01 Re: Negative result with (now()-previously_inserted_timestamp)
Previous Message Craig Ringer 2010-07-07 01:34:51 Re: BUG #5542: Query optimization problem