Thread: Return value in function/trigger

Return value in function/trigger

From
Jean-Christian Imbeault
Date:
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


Re: Return value in function/trigger

From
Stephan Szabo
Date:
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.


Re: Return value in function/trigger

From
Jean-Christian Imbeault
Date:
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


Re: Return value in function/trigger

From
Neil Conway
Date:
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