Re: Triggers on Stored Procedures

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Omer Anson" <oaanson(at)gmail(dot)com>,<pgsql-admin(at)postgresql(dot)org>
Subject: Re: Triggers on Stored Procedures
Date: 2010-12-27 18:32:18
Message-ID: 4D1887520200002500038BCC@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Resending because I just noticed that the list was not copied on the
rest of the exchange. (Omer, please keep the list copied in any
future exchanges, as it tends to make the discussion available on
search engines for those who may have similar questions.) Omer
wasn't sure about what I was proposing, so I provided this example,
which Omer said was exactly what was needed.

Omer Anson <oaanson(at)gmail(dot)com> wrote:

> Did I understand you correctly?

A simple example would probably be good:

test=# create schema pointcut;
CREATE SCHEMA
test=# create schema appconcern;
CREATE SCHEMA
test=# create schema crosscutconcern;
CREATE SCHEMA
test=# set search_path to
test-# pointcut,appconcern,crosscutconcern,public;
SET
test=# create function appconcern.addints(a int, b int)
test-# returns int language sql immutable strict
test-# as 'select $1 + $2;';
CREATE FUNCTION
test=# select addints(2,3);
addints
---------
5
(1 row)

test=# create function crosscutconcern.notifyenterfunc(funcname
text)
test-# returns void language plpgsql immutable strict as $$
test$# begin raise notice 'entering fucntion %', funcname; end;
test$# $$;
CREATE FUNCTION
test=# create function crosscutconcern.notifyleavefunc(funcname
text)
test-# returns void language plpgsql immutable strict
test-# as $$
test$# begin raise notice 'leaving fucntion %', funcname; end;
test$# $$;
CREATE FUNCTION
test=# create or replace function pointcut.addints(a int, b int)
test-# returns int language plpgsql immutable strict
test-# as $$
test$# declare resultval int;
test$# begin
test$# perform crosscutconcern.notifyenterfunc('addints');
test$# select appconcern.addints(a, b) into resultval;
test$# perform crosscutconcern.notifyleavefunc('addints');
test$# return resultval;
test$# end;
test$# $$;
CREATE FUNCTION
test=# select addints(2,3);
NOTICE: entering fucntion addints
CONTEXT: SQL statement "SELECT
crosscutconcern.notifyenterfunc('addints')"
PL/pgSQL function "addints" line 4 at PERFORM
NOTICE: leaving fucntion addints
CONTEXT: SQL statement "SELECT
crosscutconcern.notifyleavefunc('addints')"
PL/pgSQL function "addints" line 6 at PERFORM
addints
---------
5
(1 row)

Note the unqualified reference to addints was initially the bare
appconcern function and was later wrapped with crosscutting
functions by the pointcut function of the same name.

-Kevin

Browse pgsql-admin by date

  From Date Subject
Next Message Jasen Betts 2010-12-28 01:40:32 Re: Unable to install 9.0 postgre in debian-lenny
Previous Message ℓєѕℓιє ѕαмυєℓ 2010-12-27 17:09:24 Unable to install 9.0 postgre in debian-lenny