From: | "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: dynmic column names inside trigger? |
Date: | 2007-11-22 14:11:46 |
Message-ID: | 47459C32.A3DD.0030.0@indicator.be |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I don't really see how you could test a non-existing column. Here
> if old.story is not null and new.story != old.story then
> new.story = sanitize_text(new.story);
you would always use fields from OLD and NEW otherwise you can't even create the trigger.
If a table has 3 fields (field1, field2 and field3) then why would you create a trigger in which
you do something with field4. I haven't tried (because it seems so absurd) but I expect
PG to refuse to create such a trigger.
>>> Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org> 2007-11-22 14:54 >>>
On Wed, Nov 21, 2007 at 09:14:14AM +0100, Bart Degryse wrote:
> I would do something like this (not tested, but conceptually working):
Hello,
> BEGIN
> if old.story is not null and new.story != old.story then
> new.story = sanitize_text(new.story);
> end if;
> --checks on other field can be included here, eg
> if old.otherfield is not null and new.otherfield != old.otherfield then
> new.otherfield = sanitize_text(new.otherfield);
> end if;
But if I test a non-existent column for not being null I will have an
exception, no?
Otherwise this is a nice way of doing it.
Thanks,
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
From | Date | Subject | |
---|---|---|---|
Next Message | Rodrigo De León | 2007-11-22 16:06:25 | Re: SQL state: 22P02 |
Previous Message | Louis-David Mitterrand | 2007-11-22 13:54:59 | Re: dynmic column names inside trigger? |