Re: [GENERAL] CURRENT_TIMESTAMP

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: josh(at)agliodbs(dot)com, Manfred Koizar <mkoi-pg(at)aon(dot)at>, Aaron Held <aaron(at)MetroNY(dot)com>, Roberto Mello <rmello(at)cc(dot)usu(dot)edu>, Neil Conway <neilc(at)samurai(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: [GENERAL] CURRENT_TIMESTAMP
Date: 2002-09-23 20:55:48
Message-ID: 4619.1032814548@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-sql

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> I don't see how we can defend returning the start of the transaction as
> the current_timestamp.

Here's an example:

CREATE RULE foo AS ON INSERT TO mytable DO
( INSERT INTO log1 VALUES (... , now(), ...);
INSERT INTO log2 VALUES (... , now(), ...) );

I think it's important that these commands store the same timestamp in
both log tables (not to mention that any now() being stored into mytable
itself generate that same timestamp).

If you scale that up just a little bit, you can devise scenarios where
successive client-issued commands (within a single transaction) want to
store the same timestamp. After all, it's only a minor implementation
detail that you chose to fire these logging operations via a rule and
not by client-side logic.

In short, there are plenty of situations where it's critical for
application correctness that a series of commands all be able to operate
with the same value of now(). I don't think that it's wise for Postgres
to try to decide where within a transaction it's safe to advance now().
That will inevitably break some applications, and it's not obvious what
the benefit is.

In short: if you want exact current time, there's timeofday(). If you
want start of transaction time, we've got that. If you want start of
current statement time, I have two questions: why, and exactly how do
you want to define current statement, considering functions, rules,
triggers, and all that other stuff that makes it interesting?

ISTM that if a client or function wants to record intratransaction
times, it can call timeofday() at the appropriate points for itself.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message elein 2002-09-23 20:59:49 Re: OID order = INSERT order?
Previous Message Bruce Momjian 2002-09-23 20:53:20 Re: [GENERAL] CURRENT_TIMESTAMP

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2002-09-23 21:07:28 Re: NUMERIC's transcendental functions
Previous Message Bruce Momjian 2002-09-23 20:53:20 Re: [GENERAL] CURRENT_TIMESTAMP

Browse pgsql-sql by date

  From Date Subject
Next Message Roberto Mello 2002-09-23 22:01:16 Re: [GENERAL] Monitoring a Query
Previous Message Bruce Momjian 2002-09-23 20:53:20 Re: [GENERAL] CURRENT_TIMESTAMP