Performance of pl/pgsql functions?

From: Wells Oliver <wellsoliver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Performance of pl/pgsql functions?
Date: 2012-09-14 05:17:29
Message-ID: CAOC+FBUjq=uk2+9eqXnJPu8mYTUoX119T+DHw_wNLJdXysEfiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Do these tend to perform well? I have some simple formulas in functions
like so:

CREATE OR REPLACE FUNCTION public.stat_foo(a integer, b integer, c integer)
RETURNS numeric AS
$BODY$

declare ret numeric;

begin
select (a+b) / c::numeric into ret;
return round(ret, 3);
end

$BODY$
LANGUAGE plpgsql IMMUTABLE COST 100;

The reason I'm doing this is because i repeat this formula in a bunch of
views and queries, and it's easier to have one function. Would this somehow
be slower than reproducing the formula in every view its used? I'm hoping
not...

--
Wells Oliver
wellsoliver(at)gmail(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2012-09-14 05:27:02 Re: Performance of pl/pgsql functions?
Previous Message François Beausoleil 2012-09-14 03:09:07 Re: pg_dump -Fd must create directory