473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Time at end of transaction

Dear All,

Within a transaction, now() and current_timestamp are constant and give
the time that the transaction started. This is normally what you want.
But I have a case where I actually need the time that the transaction
is committed, or something similar. Is there a way to get it? Here is
the problem:

The timestamps that I am recording are "last modified" times. The
client may have kept a local copy of something, and asks the server to
"send a new copy if it has been modified since time X". This is
actually HTTP's in-modified-since behaviour.

Consider three transactions W, R1 and R2. W writes to the tables and is
long-running. R1 and R2 only read the tables and are short-running.
They are interleaved as follows:

W starts
R1 starts
R1 finishes
W finishes
R2 starts
R2 finishes

R1 and R2 come from the same client. In R2 the client asks "send me
everything that has changed since (time of R1)". It needs to get the
changes made by W, since R1 saw the state of the database before W started.

W currently finishes with a statement like this:

update ..... set last_modified_time = current_timestamp where ....;

This doesn't do what I want - I need to record the time when W will
finish and its changes become visible to other transactions, not the
time that it started.

Of course it is impossible to know when a transaction that is still in
progress will finish so some sort of trick is needed. The best that I
can think of is:

begin;
....main work of transaction, no or few locks held...
LOCK some important lock that blocks reads
update set last_modified_time = really_now
end;

Any ideas anyone?

(What happens, or should happen, to current_timestamp inside nested
transactions?)
Regards,

--Phil.


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #1
2 2730
Hi,

I think that timeofday() should solve your issue.
Just take care that this function returns text instead of timestamp... You
will have to cast it.

Patrick
-------------------------------------------------------------------------- ----------------- Patrick Fiche
email : pa***********@aqsacom.com
tél : 01 69 29 36 18
-------------------------------------------------------------------------- -----------------

-----Original Message-----
From: pg*****************@postgresql.org
[mailto:pg*****************@postgresql.org]On Behalf Of Phil Endecott
Sent: mercredi 13 octobre 2004 14:11
To: pg***********@postgresql.org
Subject: [GENERAL] Time at end of transaction
Dear All,

Within a transaction, now() and current_timestamp are constant and give
the time that the transaction started. This is normally what you want.
But I have a case where I actually need the time that the transaction
is committed, or something similar. Is there a way to get it? Here is
the problem:

The timestamps that I am recording are "last modified" times. The
client may have kept a local copy of something, and asks the server to
"send a new copy if it has been modified since time X". This is
actually HTTP's in-modified-since behaviour.

Consider three transactions W, R1 and R2. W writes to the tables and is
long-running. R1 and R2 only read the tables and are short-running.
They are interleaved as follows:

W starts
R1 starts
R1 finishes
W finishes
R2 starts
R2 finishes

R1 and R2 come from the same client. In R2 the client asks "send me
everything that has changed since (time of R1)". It needs to get the
changes made by W, since R1 saw the state of the database before W started.

W currently finishes with a statement like this:

update ..... set last_modified_time = current_timestamp where ....;

This doesn't do what I want - I need to record the time when W will
finish and its changes become visible to other transactions, not the
time that it started.

Of course it is impossible to know when a transaction that is still in
progress will finish so some sort of trick is needed. The best that I
can think of is:

begin;
....main work of transaction, no or few locks held...
LOCK some important lock that blocks reads
update set last_modified_time = really_now
end;

Any ideas anyone?

(What happens, or should happen, to current_timestamp inside nested
transactions?)
Regards,

--Phil.


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly


Protected by Polesoft Lockspam
http://www.polesoft.com/refer.html
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #2
Phil Endecott wrote:
Dear All,

Within a transaction, now() and current_timestamp are constant and give
the time that the transaction started. This is normally what you want.
But I have a case where I actually need the time that the transaction
is committed, or something similar. Is there a way to get it? Here is
the problem:


You want timeofday() - see the "date/time functions" section of the
manuals. Note that it returns text not timestamptz.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: A.M. de Jong | last post by:
In the hereunder written message I talk about point in time restore. It is now based upon the fact that there are no hardware problems or what so ever. I just would like to roll back to a...
2
by: Rajesh Garg | last post by:
I will make it simpler to look... I have DB1 - as backup for day 1 LOg1 as backup of logs T1 T2 T3 T4 T5 ...some transaction on day 2 Now i backup again DB2 Log2
2
by: Jason Priebe | last post by:
I'm a bit confused about SET TIME ZONE and its effect on PostgreSQL's date processing. In my experience with timestamps in all other *nix-based software systems, a timestamp is always a numeric...
7
by: deko | last post by:
I need to associate a Creation Date and a Modified Date with each entry in my database. How to do this? Here's what I've tried: 1) Use a separate table (tblUpdate) with Created, Modified,...
6
by: Jonathan LaRosa | last post by:
I am trying to open a recordset and I am getting an error and I can't figure out why. See code below. sqlString2 does not work. sqlString does. Clearly the problem is with the nested SELECT...
3
by: Eitan | last post by:
Hello, I have run a long transaction on the DB (sql server) For some long transaction I have got the following message : What can I do in order to run it properly ? Error Type:
13
by: Astrom33 | last post by:
Hello everyone. I am as new to this forum as I am to Microsoft Access. I am working on a case at the law firm I work at. Basically the table I have shows all point of sale (cash register)...
3
by: getmeidea | last post by:
Hi all, I have a table, account_transactions(trans_rid int primary key COMMENT 'Transaction ID', trans_date date COMMENT 'Date of transaction', ...
5
by: aj | last post by:
SQL Server SP2 9.0.3042 64-bit I recently put my first SQL Server DB in production. In the "other" database that I use (not interested in any arguments), you can indicate the desired size of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.