From: Jeff Eckermann <jeckermann@verio.net>
To: 'Andy Samuel' <andysamuel@geocities.com>
To: pgsql-general@postgresql.org
Subject: RE: Trigger
Date: Fri, 29 Jun 2001 09:29:27 -0500
Message-ID: <08CD1781F85AD4118E0800A0C9B8580B094B04@NEZU> (raw)
Use conditional logic in your function:
CREATE FUNCTION set_defval ()
RETURNS opaque AS '
BEGIN
IF NEW.fieldid = ''MODULESTATUS''
THEN NEW.defval := ''OFF'';
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER default_value_set_defval
BEFORE UPDATE ON default_value
FOR EACH ROW EXECUTE PROCEDURE set_defval();
The trigger will fire for all updates, but will be a no-op for all cases
which don't meet your criterion.
This will create a small performance penalty, but probably not enough to be
noticeable.
I don't think there is a way to have a trigger fire selectively on a given
event.
HTH
> -----Original Message-----
> From: Andy Samuel [SMTP:andysamuel@geocities.com]
> Sent: Friday, June 29, 2001 12:39 AM
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] Trigger
>
> How do I create a trigger on a table if a certain row is updated ?
> For example, a table called DefaultValue with :
> ModuleId char(10),
> FieldId char(10),
> DefVal char(3)
>
> If I update the table 'update DefaultValue set defval='OFF' where
> FieldId='MODULESTATUS' then it will fire the event.
>
> Thank you in advance
> Andy
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: jeckermann@verio.net, andysamuel@geocities.com
Subject: Re: Trigger
In-Reply-To: <08CD1781F85AD4118E0800A0C9B8580B094B04@NEZU>
References: <08CD1781F85AD4118E0800A0C9B8580B094B04@NEZU>
* 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