| From: | Jan Wieck <JanWieck(at)Yahoo(dot)com> |
|---|---|
| To: | Brian Blaha <bblaha(at)umr(dot)edu> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: SQL function triggers |
| Date: | 2002-10-15 18:46:03 |
| Message-ID: | 3DAC626B.4DEB45E8@Yahoo.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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(at)Yahoo(dot)com #
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2002-10-15 18:54:23 | Re: Messy Casts, Is there a better way? |
| Previous Message | Josh Berkus | 2002-10-15 17:27:51 | Re: Use of reference table ('look-up-table') and FK constraint |