From: | Sean Chittenden <sean(at)chittenden(dot)org> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: plpgsql lacks generic identifier for record in triggers... |
Date: | 2004-11-25 01:23:06 |
Message-ID: | 8F7983FE-3E80-11D9-841B-000A95C705DC@chittenden.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-hackers |
> Now that pgmemcache is getting more use, I've heard a couple of groans
> regarding the need to have two functions with exactly the same code
> body. This is necessary because there is no generic way of handling
> NEW/OLD. For example:
[snip] Err... wait, this is a classic case of send first then
finishing to pondering the gripe.
> db=# CREATE FUNCTION schma.tbl_inval() RETURNS TRIGGER AS 'BEGIN
> EXECUTE public.mc_init();
> EXECUTE public.mc_delete(''mc_key'');
> RETURN ROW;
> END;' LANGUAGE 'plpgsql';
> db=# CREATE TRIGGER tbl_inval_trg AFTER INSERT OR UPDATE OR DELETE ON
> schma.tbl FOR EACH ROW EXECUTE PROCEDURE schma.tbl_inval();
A statement trigger should be used instead since the return value is
ignored (and NULL can be used to satisfy the need for return to
actually return something). When updating dynamic keys, you always
need to be explicit regarding NEW/OLD to get the data version, but for
static keys, statement triggers are the way to go. Ex:
> db=# CREATE FUNCTION schma.tbl_inval() RETURNS TRIGGER AS 'BEGIN
> EXECUTE public.mc_init();
> EXECUTE public.mc_delete(''mc_key'');
> RETURN NULL;
> END;' LANGUAGE 'plpgsql';
> db=# CREATE TRIGGER tbl_inval_trg AFTER INSERT OR UPDATE OR DELETE ON
> schma.tbl FOR EACH STATEMENT EXECUTE PROCEDURE schma.tbl_inval();
Very nice. -sc
--
Sean Chittenden
From | Date | Subject | |
---|---|---|---|
Next Message | Sean Chittenden | 2004-11-25 01:42:36 | Stack not being popped correctly (was: Re: [HACKERS] plpgsql lacks generic identifier for record in triggers...) |
Previous Message | Sean Chittenden | 2004-11-25 01:06:11 | plpgsql lacks generic identifier for record in triggers... |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2004-11-25 01:25:58 | Re: -V, --version -- deprecated? |
Previous Message | Sean Chittenden | 2004-11-25 01:06:11 | plpgsql lacks generic identifier for record in triggers... |