From: | Alban Hertroys <haramrae(at)gmail(dot)com> |
---|---|
To: | pgsql-general General <pgsql-general(at)postgresql(dot)org> |
Subject: | SQL functions and triggers? |
Date: | 2014-11-25 20:41:12 |
Message-ID: | 6A1FF817-6099-4250-AA70-0626F3137697@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi all,
In the past, when writing trigger functions, I’ve always used pl/pgsql without giving it a second thought. Today I was modifying a database creation script that was originally intended for Firebird to work with Postgres and the example trigger procedures in there were very close to pure SQL.
Hence, I started rewriting them as SQL functions, but is that really possible? The return-type for trigger functions is usually ‘returns trigger’, which I don’t know how to translate to SQL. Next to that, what should the SQL statement inside the function be returning?
This got a bit puzzling and now I wonder whether this is possible at all? And if so, what’s the correct syntax?
Say I have the below, how to actually return a value of type trigger?:
create or replace function pUpdateFoo()
returns trigger
as $$
update Bar
set baz = baz + NEW.feep - OLD.feep
where foo = NEW.foo;
$$;
create trigger tUpdateFoo
after update on Foo
for each row
execute procedure pUpdateFoo();
Glad to finally have a proper opportunity to apply PG again - it’s been too long!
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.
From | Date | Subject | |
---|---|---|---|
Next Message | Bill Moran | 2014-11-25 21:01:05 | Re: SQL functions and triggers? |
Previous Message | Willy-Bas Loos | 2014-11-25 19:09:14 | users per database |