Thread: Triggers | rules for column updates

Triggers | rules for column updates

From
Szentpali Janos
Date:
Hi!

I want to prevent any changes to a tuple if a field of the tuple has a
certain value. Let's say I have a table with column col_1, col_2, col_3.
I want to create something that will prevent updating col_2 and col_3 if
and only if col_1 is say "1".
Can I use a rule to do that. Can I somehow detect in a trigger function
the name of the columns that are updated? If I could do that, it would
be easy to create a trigger that would do the job.
I am also opened to other kind of solutions that you might know of.
Any help will be appreciated ;)

--
Szentpáli János


Re: Triggers | rules for column updates

From
"A. Kretschmer"
Date:
am  Mon, dem 03.03.2008, um 15:47:58 +0200 mailte Szentpali Janos folgendes:
> Hi!
>
> I want to prevent any changes to a tuple if a field of the tuple has a
> certain value. Let's say I have a table with column col_1, col_2, col_3.
> I want to create something that will prevent updating col_2 and col_3 if
> and only if col_1 is say "1".
> Can I use a rule to do that. Can I somehow detect in a trigger function

I think, a RULE isn't the solution, but you can use a BEFORE UPDATE -
Trigger to check if OLD.col_1 = 1 and, in this case, RAISE an error.



Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net