Re: function return value inside a trigger function - Mailing list pgsql-general

From Tom Lane
Subject Re: function return value inside a trigger function
Date
Msg-id 10581.1348709195@sss.pgh.pa.us
Whole thread Raw
In response to function return value inside a trigger function  (joao viegas <jtamviegas@yahoo.co.uk>)
Responses Re: function return value inside a trigger function
List pgsql-general
joao viegas <jtamviegas@yahoo.co.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


pgsql-general by date:

Previous
From: Stephen Frost
Date:
Subject: Re: PostgreSQL, OLAP, and Large Clusters
Next
From: David Johnston
Date:
Subject: Re: unc paths, like and backslashes on 8.4