I am trying to call a function inside of a trigger in postgres. Basically I have a function,
c.check_level(bigint, integer)which returns a boolean value.
I would like to call this function inside of a trigger as follows:
CREATE OR REPLACE FUNCTION c.check_level_tg()
RETURNS trigger AS
$BODY$
DECLARE
parent_id int8;
level int;
result bool;
begin
parent_id := NEW.fk_parent;
level := NEW.level;
select * from c.check_category_level(parent_id, level) as result;
if (result) then
return (NEW);
else
return(NULL);
end if;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION c.check_category_level_tg()
OWNER TO postgres;
When I try to put data in the table on which this trigger resides, I get an error: "ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL function".
The function c.check_level works properly when run in isolation.
select c.check_category_level(parent_id, level) INTO result;
– joop Dec 3 '13 at 12:55CHECK
constraint on it? – joop Dec 3 '13 at 13:27