pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSQL function triggers
3+ messages / 3 participants
[nested] [flat]
* SQL function triggers
@ 2002-10-15 06:06 Brian Blaha <bblaha@umr.edu>
0 siblings, 2 replies; 3+ messages in thread
From: Brian Blaha @ 2002-10-15 06:06 UTC (permalink / raw)
To: pgsql-sql
I would like to write a function as a set of SQL statements, and then
use that function
in a trigger. However, since triggers require a return type of opaque,
and SQL functions
cannot return type opaque, this doesn't look possible. Am I missing
something? The SQL
that I would expect to do this is below. Incidentally, on an insert,
would the trigger fire
once, twice, or infinitely?
create table test(
a integer,
b integer
) without oids;
create function test_func( test.a%TYPE )
RETURNS ?????
AS
'update test set b = a where a = $1;'
language SQL
with (isstrict);
create trigger test_trig after update
on test for each row
execute procedure test_func( a );
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: SQL function triggers
@ 2002-10-15 14:07 Tom Lane <tgl@sss.pgh.pa.us>
parent: Brian Blaha <bblaha@umr.edu>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2002-10-15 14:07 UTC (permalink / raw)
To: Brian Blaha <bblaha@umr.edu>; +Cc: pgsql-sql
Brian Blaha <bblaha@umr.edu> writes:
> I would like to write a function as a set of SQL statements, and then
> use that function
> in a trigger. However, since triggers require a return type of opaque,
> and SQL functions
> cannot return type opaque, this doesn't look possible.
You could call a SQL function from a trigger, but it can't be a trigger
itself; at present triggers have to be in C, plpgsql, or pltcl (maybe
plpython? Not sure about that one).
For what you are doing (transferring info from one table to another)
I suspect a rule might work better than a trigger anyway.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: SQL function triggers
@ 2002-10-15 18:46 Jan Wieck <JanWieck@Yahoo.com>
parent: Brian Blaha <bblaha@umr.edu>
1 sibling, 0 replies; 3+ messages in thread
From: Jan Wieck @ 2002-10-15 18:46 UTC (permalink / raw)
To: Brian Blaha <bblaha@umr.edu>; +Cc: pgsql-sql
Brian Blaha wrote:
>
> I would like to write a function as a set of SQL statements, and then
> use that function
> in a trigger. However, since triggers require a return type of opaque,
> and SQL functions
> cannot return type opaque, this doesn't look possible. Am I missing
> something? The SQL
> that I would expect to do this is below. Incidentally, on an insert,
> would the trigger fire
> once, twice, or infinitely?
>
> create table test(
> a integer,
> b integer
> ) without oids;
>
> create function test_func( test.a%TYPE )
> RETURNS ?????
> AS
> 'update test set b = a where a = $1;'
> language SQL
> with (isstrict);
>
> create trigger test_trig after update
> on test for each row
> execute procedure test_func( a );
If you intend to modify the updated row only with information available
in the row itself (as in your example), a BEFORE trigger in PL/pgSQL
modifying and returning NEW should get the job done.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-10-15 18:46 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 06:06 SQL function triggers Brian Blaha <bblaha@umr.edu>
2002-10-15 14:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-10-15 18:46 ` Jan Wieck <JanWieck@Yahoo.com>
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