Re: pl/pgsql trigger: syntax error at or near "ELSEIF" - Mailing list pgsql-general

From Alban Hertroys
Subject Re: pl/pgsql trigger: syntax error at or near "ELSEIF"
Date
Msg-id 41E7BAAC.1080401@magproductions.nl
Whole thread Raw
In response to pl/pgsql trigger: syntax error at or near "ELSEIF"  (Roman Neuhauser <neuhauser@chello.cz>)
Responses Re: pl/pgsql trigger: syntax error at or near "ELSEIF"
List pgsql-general
Roman Neuhauser wrote:
> Hello, what is the parser trying to tell me? (7.4.2 if it matters)
> test'#       ELSEIF TG_OP = ''DELETE'' THEN

You typed ELSEIF, the parser doesn't know what that means (It's either
ELSIF or ELSE IF).

> On a related note: if I replace NEW with OLD in the second UPDATE (in the
> ELSEIF branch), I get:
> What's wrong with that?

OLD doesn't exist in INSERT triggers, only in UPDATE and DELETE
triggers. A record in an INSERT trigger is by definition a new record,
an old record wouldn't make sense.

IMHO, it would be better to write two or three different triggers (one
on INSERT, the other on DELETE, and maybe a third on UPDATE) than
writing a single and trying to figure out which of those three it was in
the trigger.

Alban Hertroys.

pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: pl/pgsql trigger: syntax error at or near "ELSEIF"
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Cursor bug?