Return value in function/trigger

Started by Jean-Christian Imbeaultover 23 years ago4 messagesgeneral
Jump to latest
#1Jean-Christian Imbeault
jc@mega-bucks.co.jp

I have created a trigger and the function executed by the trigger.
However the function merely updates values in a table and doesn't return
any result/value. what is the correct way of "returning" nothing?

I have written this but using "return new" seems pointless as I don't
need(?) to return anything.

create or replace function update_invoice_price() returns opaque as '
begin
update invoices set total_price=(select sum(price) from invoice_li
where invoice_id=new.invoice_id) where id=new.invoice_id;
return new;
end;
' language 'plpgsql' with (iscachable);

create trigger update_invoice_li_price after update
on invoice_li for each row
execute procedure update_invoice_price();

Thanks!

Jc

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Jean-Christian Imbeault (#1)
Re: Return value in function/trigger

On Wed, 20 Nov 2002, Jean-Christian Imbeault wrote:

I have created a trigger and the function executed by the trigger.
However the function merely updates values in a table and doesn't return
any result/value. what is the correct way of "returning" nothing?

You could return NULL but new is probably just as good.

#3Jean-Christian Imbeault
jc@mega-bucks.co.jp
In reply to: Stephan Szabo (#2)
Re: Return value in function/trigger

Stephan Szabo wrote:

You could return NULL but new is probably just as good.

Which is better/faster and why? I would think there is some overhead in
returning NEW whereas returning NULL would have less?

Jc

#4Neil Conway
neilc@samurai.com
In reply to: Jean-Christian Imbeault (#3)
Re: Return value in function/trigger

Jean-Christian Imbeault <jc@mega-bucks.co.jp> writes:

Which is better/faster and why? I would think there is some overhead
in returning NEW whereas returning NULL would have less?

I'd suspect returning NULL (or just 'RETURN;') would be a few cycles
faster. However, unless the tuple you're returning is *really* large, I
doubt it would make a significant performance difference.

Cheers,

Neil

--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC