UPDATE with help of RULES

Поиск
Список
Период
Сортировка
Искать

UPDATE with help of RULES

От:
Volker Krey <v.krey@fz-juelich.de>
Дата:
Hello,

I have a table with a number of columns (e.g. one) plus a date column, 
which is by default set to current_date.

CREATE TABLE test
(
column_a varchar(10),
last_altered date DEFAULT current_date,
PRIMARY KEY (column_a)
);

Now I want to create a rule that updates the column last_altered of a 
particular row to the date when the row has been altered, i.e. updated 
last time. Creating a rule wasn't a problem, but whatever I tried ended 
in a loop, because the rule reacts with an update on an update and so on...
I also tried to insert a new row with the current_date after deleting 
the original one. The DELETE worked okay, but the INSERT afterwards 
always failed and so I ended with deleting instead of updating the table 
entry. If I do the INSERT first and then the DELETE there is no such 
problem, but this of course only works if the UPDATE includes a change 
of column_a (PRIMARY KEY).
Is there a simple way of implementing such an automatic update of the 
date entry? If it's not possible on the basis of rules, maybe there is 
another way of achieving this aim?

Thanks for your help, Volker.

-- 
Volker Krey
v.krey@fz-juelich.de

Re: UPDATE with help of RULES

От:
Bruno Wolff III <bruno@wolff.to>
Дата:
On Mon, Nov 10, 2003 at 14:06:22 +0100,
  Volker Krey  wrote:
> Hello,
> 
> Now I want to create a rule that updates the column last_altered of a 
> particular row to the date when the row has been altered, i.e. updated 
> last time. Creating a rule wasn't a problem, but whatever I tried ended 
> in a loop, because the rule reacts with an update on an update and so on...

I think you want to use a before trigger to do this.
FAQ