Re: BUG #5996: CURRENT_TIMESTAMP uses often undesired TRANSACTION_TIMESTAMP, instead of STATEMENT_TIMESTAMP - Mailing list pgsql-bugs

From Robert Haas
Subject Re: BUG #5996: CURRENT_TIMESTAMP uses often undesired TRANSACTION_TIMESTAMP, instead of STATEMENT_TIMESTAMP
Date
Msg-id BANLkTikAwB9G8ckQMKhgwuFeOJsw0bFX1Q@mail.gmail.com
Whole thread Raw
In response to BUG #5996: CURRENT_TIMESTAMP uses often undesired TRANSACTION_TIMESTAMP, instead of STATEMENT_TIMESTAMP  ("Brian S. Krug" <bkrug@usatech.com>)
List pgsql-bugs
On Thu, Apr 28, 2011 at 3:33 PM, Brian S. Krug <bkrug@usatech.com> wrote:
>
> The following bug has been logged online:
>
> Bug reference: =A0 =A0 =A05996
> Logged by: =A0 =A0 =A0 =A0 =A0Brian S. Krug
> Email address: =A0 =A0 =A0bkrug@usatech.com
> PostgreSQL version: 9.0.3
> Operating system: =A0 Solaris
> Description: =A0 =A0 =A0 =A0CURRENT_TIMESTAMP uses often undesired
> TRANSACTION_TIMESTAMP, instead of STATEMENT_TIMESTAMP
> Details:
>
> CURRENT_TIMESTAMP (and CURRENT_DATE, CURRENT_TIME) return the time of the
> start of the transcaction - which seems to be right after the end of the
> last transaction. Thus, if you use pooled connections, CURRENT_TIMESTAMP
> will return the time of the last COMMIT. This is often unintended behavio=
r.
> This tripped me up significant and I would anticipate that many have fall=
en
> into the same trap. I recommend that CURRENT_TIMESTAMP functions as
> STATEMENT_TIMESTAMP instead of as TRANSACTION_TIMESTAMP.

I've been bitten by this too, but I doubt we're likely to want to
change it at this point for reasons of backward compatibility.  The
SQL standard may have something to say about it, too.

But as for pooled connections, it would seem unwise to multiplex a
server connection across different sessions while leaving a
transaction open.  Presumably each client should commit after it
finishes its own work.

--=20
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

pgsql-bugs by date:

Previous
From: Robert Haas
Date:
Subject: Re: help
Next
From: Robert Haas
Date:
Subject: Re: BUG #6005: ALTER ROLE ... VALID UNTIL 'infinity' crashes postmaster on a fresh install