Skip site navigation (1) Skip section navigation (2)

auto update dates

From: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>
To: Postgresql Novice List <pgsql-novice(at)postgresql(dot)org>
Subject: auto update dates
Date: 2002-05-23 13:02:51
Message-ID: 20020523130251.GB14031@campbell-lange.net (view raw or flat)
Thread:
Lists: pgsql-novice
Sorry - I seem to be bombarding the list. I AM reading my copy of Bruce
Momjian's book quite closely, I promise!

I'm trying to make a rule to automatically update the time, date and
timestamp 'modified' fields when a row is updated.

This is what I have tried:

	create rule ideas_insert_datetime_mod as on update to ideas
	do
		update ideas
		set d_modified = CURRENT_DATE, 
		t_modified = CURRENT_TIME,
		ts_modified = CURRENT_TIMESTAMP

This creates a cycle condition, and the rule does not operate.

Do I instead need to write a function and then trigger it after each
update action? I have 3 tables each with similar columns, with the same
column names, which I wish to update in the same way.

Thanks for any help.
Rory
-- 
Rory Campbell-Lange 
<rory(at)campbell-lange(dot)net>
<www.campbell-lange.net>

Responses

pgsql-novice by date

Next:From: Joel BurtonDate: 2002-05-23 14:23:51
Subject: Re: auto update dates
Previous:From: Joshua b. JoreDate: 2002-05-23 12:35:48
Subject: Re: when to use char, varchar or text

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group