Re: PL/pgSQL triggers ON INSERT OR UPDATE

From: "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>
To: san(at)cobalt(dot)rmnet(dot)it
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: PL/pgSQL triggers ON INSERT OR UPDATE
Date: 2001-10-23 16:31:12
Message-ID: 20011023163112.15909.qmail@ns.krot.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice pgsql-sql

First, I may be wrong but I do think they would prefer if you did not cross-post (especially to hackers).

Second I think it probably make more sense to make two different triggers here.

If you really wanted to do it that way you might want to try executing that part.

Regards,

Aasmund.

On Mon, 22 Oct 2001 23:25:44 +0200, san(at)cobalt(dot)rmnet(dot)it wrote:
> Hello, I'm trying to set up a trigger on insert or update
> but when using the predefined variable ``OLD'' I get a
> NOTICE from the trigger function about OLD not being defined yet.
>
> Of course OLD is not defined when the function is triggered on INSERT
> event, and I did not mention it if not inside a conditional block
> checking for the TG_OP variable being 'UPDATE'.
>
> For better understanding here is some code:
>
> BEGIN
> IF TG_OP = 'UPDATE' THEN
> IF OLD.id <> NEW.id THEN
> -- do the work
> END IF
> END IF;
> END;
>
> Even when TG_OP != 'UPDATE' (INSERT event) I still get an error
> message from the pl/pgsql compiler (the first time the trigger is fired).
>
> What should I do then ? Is it still possible to use the same function
> for UPDATE OR INSERT events ?
>
> TIA
>
> --san;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

Aasmund Midttun Godal

aasmund(at)godal(dot)com - http://www.godal.com/
+47 40 45 20 46

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Barry Lind 2001-10-23 17:04:27 Re: storing binary data
Previous Message Bruce Momjian 2001-10-23 16:23:18 Re: [GENERAL] To Postgres Devs : Wouldn't changing the selectlimit

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2001-10-23 16:51:17 Re: Concatenating strings
Previous Message Tom Lane 2001-10-23 15:01:59 Re: Concatenating strings

Browse pgsql-sql by date

  From Date Subject
Next Message Aasmund Midttun Godal 2001-10-23 17:08:08 Error codes as numbers or in other languages etc.
Previous Message Cory Wright 2001-10-23 15:24:02 Re: Auto Increment