Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 29EA02E0047 for ; Thu, 22 Nov 2007 10:11:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 71430-07 for ; Thu, 22 Nov 2007 10:11:55 -0400 (AST) Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id AA28C2E0045 for ; Thu, 22 Nov 2007 10:11:54 -0400 (AST) Received: from webaccess.indicator.be ([10.100.1.7]) by interscan.indicator.com with InterScan Message Security Suite; Thu, 22 Nov 2007 15:09:28 +0100 Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Thu, 22 Nov 2007 15:11:51 +0100 Message-Id: <47459C32.A3DD.0030.0@indicator.be> X-Mailer: Novell GroupWise Internet Agent 7.0.1 Date: Thu, 22 Nov 2007 15:11:46 +0100 From: "Bart Degryse" To: Subject: Re: dynmic column names inside trigger? References: <20071120161258.GA27106@apartia.fr><4743F6E5.A3DD.0030.0@indicator.be> <20071122135403.GA10426@apartia.fr> In-Reply-To: <20071122135403.GA10426@apartia.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__PartD6F0D932.0__=" X-imss-version: 2.049 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/118 X-Sequence-Number: 29646 --=__PartD6F0D932.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable I don't really see how you could test a non-existing column. Here > if old.story is not null and new.story !=3D old.story then > new.story =3D 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 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 !=3D old.story then > new.story =3D sanitize_text(new.story); > end if; > --checks on other field can be included here, eg > if old.otherfield is not null and new.otherfield !=3D old.otherfield = then > new.otherfield =3D sanitize_text(new.otherfield); > end if; But if I test a non-existent column for not being null I will have an=20 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 --=__PartD6F0D932.0__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Description: HTML
I don't really see how you could test a non-existing column. = Here
> if old.story is not null and new.story !=3D old.story then
>= ;   new.story =3D 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@apa= rtia.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 !=3D old.story = then
>   new.story =3D sanitize_text(new.story);
> = end if;
> --checks on other field can be included here, eg
> = if old.otherfield is not null and new.otherfield !=3D old.otherfield = then
>   new.otherfield =3D sanitize_text(new.otherfield);<= BR>> 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
--=__PartD6F0D932.0__=--