Re: function return value inside a trigger function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: joao viegas <jtamviegas(at)yahoo(dot)co(dot)uk>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: function return value inside a trigger function
Date: 2012-09-27 01:26:35
Message-ID: 10581.1348709195@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

joao viegas <jtamviegas(at)yahoo(dot)co(dot)uk> writes:
> does anybody knows how can I have something like:
> select function_that_returns_int(NEW.field1) into NEW.field2;

Works for me ...

create table fooey (q1 int, q2 int);

create function myt() returns trigger language plpgsql as $$
begin
select abs(new.q1) into new.q2;
return new;
end$$;

create trigger mytrig before insert on fooey for each row
execute procedure myt();

insert into fooey values(-42, 77);

select * from fooey;
q1 | q2
-----+----
-42 | 42
(1 row)

Perhaps you should show a full example of what you're doing.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-09-27 02:32:21 Re: unc paths, like and backslashes on 8.4
Previous Message Stephen Frost 2012-09-27 01:15:35 Re: PostgreSQL, OLAP, and Large Clusters