473,386 Members | 2,129 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.

Modification Dates

Hi

Many people are asking how to automatically update columns containing a
modification date on updates. I'm wondering if the only solutions in
the current pgsql really are...

- adding "modification=NOW()" to every update query "manually"
- defining a trigger called on updates

While addings things "manually" is quite clumsy, a trigger actually
causes a second update thus slowing down the Db.

As far as I know, rules don't help due to circular conditions (an
update causes an update causes an update...) and functions stil require
to add stuff to each and every update. But I could be wrong. Please -
anyone - enlighten me, us and the world :-)

I'm dreaming of something like the following:
CREATE TABLE table (modified TIMESTAMP NOT NULL DEFAULT NOW(), data
INTEGER)
CREATE RULE table_rule AS ON UPDATE TO table DO ADD modified=NOW()
INSERT INTO TABLE table (data) VALUES (1) <-- modified is defaulted
to NOW()
UPDATE TABLE table SET data=2 <-- modified is implicitly (by rule)
set to NOW()
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #1
7 3101
On Sat, 27 Sep 2003, Sven Schwyn wrote:
Hi

Many people are asking how to automatically update columns containing a
modification date on updates. I'm wondering if the only solutions in
the current pgsql really are...

- adding "modification=NOW()" to every update query "manually"
- defining a trigger called on updates

While addings things "manually" is quite clumsy, a trigger actually
causes a second update thus slowing down the Db.

I suspect you're misunderstanding something about triggers, an on update
trigger setting a such a field to the current timestamp shouldn't be causing a
second update. You're actually doing an update statement within the trigger I
presume? That's not the way, just set NEW.modified to the value you want,
eg. the current timestamp.
As far as I know, rules don't help due to circular conditions (an
update causes an update causes an update...) and functions stil require
to add stuff to each and every update. But I could be wrong. Please -
anyone - enlighten me, us and the world :-)


Does an update within a rule get rewritten by the rule system if it's on the
same table as the rule?
Nigel Andrews

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #2
Sven Schwyn wrote:
Hi

Many people are asking how to automatically update columns containing
a modification date on updates. I'm wondering if the only solutions in
the current pgsql really are...


I'd like to know this myself, maybe views would work?
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #3
Hi again

Got it, quite obvious too. The trigger has to be called BEFORE the
UPDATE, not AFTER. (Hmmm, very obvious even.)

CREATE TRIGGER _modified BEFORE UPDATE ON any_table FOR EACH ROW
EXECUTE PROCEDURE
touch();

That does the trick!

Greets, -sven
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #4
Hi Nigel
I suspect you're misunderstanding something about triggers, an on
update
trigger setting a such a field to the current timestamp shouldn't be
causing a
second update. You're actually doing an update statement within the
trigger I
presume? That's not the way, just set NEW.modified to the value you
want,
eg. the current timestamp.


I'm doing it this way but I've read somewhere that this causes a second
UPDATE. If that's not the case, the better!

However, I seem to be missing something else. All my tables contain a
column...

modified TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()

The following function exists...

CREATE FUNCTION touch() RETURNS OPAQUE AS 'BEGIN new.modified = NOW();
RETURN ne
w; END;' LANGUAGE 'plpgsql';

And all tables have the following trigger defined...

CREATE TRIGGER _modified AFTER UPDATE ON any_table FOR EACH ROW EXECUTE
PROCEDURE
touch();

All this returned no errors. I do get a notice though:
NOTICE: CreateTrigger: changing return type of function touch() from
OPAQUE to TRIGGER

I had the impression that now the modified-column should be set to the
NOW() whenever an UPDATE is made on the row. That's not the case, the
value remains unchanged. What's wrong with this?

Your help is greatly apprechiated! -sven
---------------------------(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 12 '05 #5
Sven Schwyn <ze**@bluewin.ch> writes:
CREATE TRIGGER _modified AFTER UPDATE ON any_table FOR EACH ROW
EXECUTE PROCEDURE
touch();


You want BEFORE UPDATE here. AFTER UPDATE happens, well, after the
update. :)

-Doug

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #6
Hi,
i use Access as a frontend via ODBC to an Linux-based postgresql.

I have a problem in a form where I use a lot of subforms. In some
cases ( i couldn't detect when - but I really try to) the form and Access
hangs.

The only way to close the form is to close Access via "cross" (upper right
corner).
If I try then to view once again the form I get the following error message:
"Sie konnen diese Aktion momentan nicht ausfuhren" means : "You counldn't do
this now".

Has anybody an idea - why this is hanging or where i can start to debug.

-Elmar


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #7

Hi .. i have the same problem ..

If i left forms open i would get the same error and could not close them unless i would change to design mode ..

and solved it this way :

In the access db open the database then in the menu open Tools --> Options Then go in then Advanced section and set the ODBC Update interval to 32766 (instead of 1500)

Next run regedit on the windows machine that opens the db and go to the following key:

HKLM --> Software --> Microsoft --> Jet --> 4.0 --> ODBC and change the following key : (If you use access 97 than jet will be 3.5 and not 4.0)

Connection Timeout from 600 to 0 (Remember to use decimal and not hexadecimal when you edit)
It took me about 5 motnhs to understand this problem but finally it worked!!!

Best Regards,

Fabrizio Mazzoni
Macron Srl
On Mon, 29 Sep 2003 17:34:22 +0200
"E. Zorn (RDG-rational) postsql" <po*****@rdg-rational.de> wrote:

Hi,
i use Access as a frontend via ODBC to an Linux-based postgresql.

I have a problem in a form where I use a lot of subforms. In some
cases ( i couldn't detect when - but I really try to) the form and Access
hangs.

The only way to close the form is to close Access via "cross" (upper right
corner).
If I try then to view once again the form I get the following error message:
"Sie konnen diese Aktion momentan nicht ausfuhren" means : "You counldn't do
this now".

Has anybody an idea - why this is hanging or where i can start to debug.

-Elmar


---------------------------(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


---------------------------(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 12 '05 #8

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

Similar topics

3
by: stan | last post by:
I am working on some documentation in html format and I would really like to display the date the html file, itself was modified. I am writing my documentation in vi and the html server involved is...
0
by: Marco Segurini | last post by:
HI, my form contains a combobox and a propertygrid control. At each string of the combobox is associated an object. When I select a string of the combobox the associated object is selected in...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
3
by: MarcJoseph | last post by:
I have a database that is shared my multiple users who enter and update records on a weekly basis. Is there a way I can add a field to my main data table that will automatically generate the...
13
by: ts-dev | last post by:
Is it possible to prevent modification of a python file once its been deployed? File permissions of the OS could be used..but that doesn't seem very secure. The root of my question is verifying...
4
by: MLH | last post by:
Would like to extract list of database objects in A97 database and each of their last-modified dates. What's the best way to proceed? And, is the last-modified date a property I can read in a...
0
by: nichele | last post by:
Hi all, for troubleshooting purpose, I would like to add to all my tables (and for all records) the creation and modification timestamp fields. Do you know if this is a common practice ? Do you...
2
by: Unpopular | last post by:
void directory::modification()//??????????? { clrscr(); cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ "; cout<< "\n\t=====@ @ @ @ @ @ @@...
4
by: gleery | last post by:
It's often for many pages to share a head part, and if we need to modify the head part, we need to do the same to all other pages. So I wonder if there exists a way to make it easier. How about...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.