Re: [GENERAL] Creating Triggers - Mailing list pgsql-general

From Ed Loehr
Subject Re: [GENERAL] Creating Triggers
Date
Msg-id 38863E6E.1D0BFADB@austin.rr.com
Whole thread Raw
In response to psql problem describing tables  (Sarah Officer <officers@aries.tucson.saic.com>)
List pgsql-general
Sarah Officer wrote:
>
> - A value must be returned if a return type is specified.  The old &
> new records are available as return values from the plpgsql
> function.

Unfortunately, OLD and NEW are only available in the function that's
directly called by the trigger, not subsequent functions in the call
chain, IIRC.

> - The body of a plpgsql function looks like sql except for reference
> to old and new.  The SQL part of the function must be enclosed with
> 'begin' and 'end;' or there will be a compiler error at run time.

What goes between 'begin' and 'end' are PL/pgSQL statements, of which
SQL is almost a subset.  PL/pgSQL also has a number of plain vanilla
programming language constructs (if-then, loops, etc.).

> - If a trigger function is dropped and recreated, the corresponding
> trigger must also be dropped and recreated.  Otherwise postgres
> 6.5.3 will give a runtime error that the cache lookup failed.

More generally, any function that gets dropped/recreated requires all
the functions/triggers above it in the call chain to be recreated,
IIRC.

Cheers,
Ed Loehr

pgsql-general by date:

Previous
From: "Sean Carmody"
Date:
Subject: RE: [GENERAL] Problems with operator '%' within a select
Next
From: "Ing. Roberto Andrade Fonseca"
Date:
Subject: Benchmarks for pgsql?