Re: Triggers on Stored Procedures

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: Triggers on Stored Procedures
Дата
Msg-id 4D1887520200002500038BCC@gw.wicourts.gov
обсуждение исходный текст
Ответ на Triggers on Stored Procedures  (Omer Anson <oaanson@gmail.com>)
Список 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@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

В списке pgsql-admin по дате отправления:

Предыдущее
От: ℓєѕℓιє ѕαмυєℓ
Дата:
Сообщение: Unable to install 9.0 postgre in debian-lenny
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: Unable to install 9.0 postgre in debian-lenny