Transactions and timestamps

Started by Daniel Åkerudover 24 years ago3 messagesgeneral
Jump to latest
#1Daniel Åkerud
zilch@home.se

If I do

BEGIN
UPDATE some_session set time_stop = CURRENT_TIMESTAMP
UPDATE another_session set time_start = CURRENT_TIMESTAMP
END

Is there any chance the current_timestamp will be different?

Do I have to first select current_timestamp and then update with a variable? (function?)

---
Daniel Åkerud

[ Don't underestimate the power of stupid people in large groups]

#2Richard Huxton
dev@archonet.com
In reply to: Daniel Åkerud (#1)
Re: Transactions and timestamps

Please don't post HTML to the mailing list - it makes quoting difficult...

From: "Daniel �kerud" <zilch@home.se>

If I do

BEGIN
UPDATE some_session set time_stop = CURRENT_TIMESTAMP
UPDATE another_session set time_start = CURRENT_TIMESTAMP
END

Is there any chance the current_timestamp will be different?

=reply=

If you try your example by hand (with a suitable pause) you'll see
CURRENT_TIMESTAMP and the now() function return the time at the start of the
transaction. You use timeofday() IIRC to get the "real" current time.

HTH

- Richard Huxton

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Daniel Åkerud (#1)
Re: Transactions and timestamps

=?iso-8859-1?Q?Daniel_=C5kerud?= <zilch@home.se> writes:

If I do

BEGIN
UPDATE some_session set time_stop =3D CURRENT_TIMESTAMP
UPDATE another_session set time_start =3D CURRENT_TIMESTAMP
END

Is there any chance the current_timestamp will be different?

No. CURRENT_TIMESTAMP is actually the time of the start of the
transaction.

regards, tom lane