From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Omer Anson <oaanson@gmail.com>
To: pgsql-admin@postgresql.org
Subject: Re: Triggers on Stored Procedures
Date: Mon, 27 Dec 2010 12:32:18 -0600
Message-ID: <4D1887520200002500038BCC@gw.wicourts.gov> (raw)
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@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: Kevin.Grittner@wicourts.gov, oaanson@gmail.com
Subject: Re: Triggers on Stored Procedures
In-Reply-To: <4D1887520200002500038BCC@gw.wicourts.gov>
References: <4D1887520200002500038BCC@gw.wicourts.gov>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox