From: Bart Degryse <Bart.Degryse@indicator.be>
To: pgsql-sql@postgresql.org
Subject: Re: dynmic column names inside trigger?
Date: Thu, 22 Nov 2007 15:11:46 +0100
Message-ID: <47459C32.A3DD.0030.0@indicator.be> (raw)
In-Reply-To: <20071122135403.GA10426@apartia.fr>
References: <20071120161258.GA27106@apartia.fr>
<4743F6E5.A3DD.0030.0@indicator.be>
<20071122135403.GA10426@apartia.fr>
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@apartia.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?
http://www.postgresql.org/docs/faq
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: Bart.Degryse@indicator.be
Subject: Re: dynmic column names inside trigger?
In-Reply-To: <47459C32.A3DD.0030.0@indicator.be>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox