Re: plpgsql default arguments

From: Neil Conway <neilc(at)samurai(dot)com>
To: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
Cc: Greg Lindstrom <greg(dot)lindstrom(at)novasyshealth(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql default arguments
Date: 2005-04-15 04:09:26
Message-ID: 425F3E76.7090404@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Pavel Stehule wrote:
> CREATE OR REPLACE FUNCTION foo(integer, integer) RETURNS integer AS $$
> BEGIN
> RETURN $1 + $2;
> END; $$ LANGUAGE plpgsql;
>
> CREATE OR REPLACE FUNCTION foo(integer) RETURNS integer AS $$
> BEGIN
> RETURN foo($1,10); -- 10 is "default" value
> END; $$ LANGUAGE plpgsql;

Note that if you define the "short cut function" in SQL (the second one
above that supplies the default argument), you can take advantage of
function inlining. Granted, it's probably not a huge win, but if all the
function does is return the result of evaluating another function, it
need not be pl/pgsql anyway.

-Neil

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-04-15 04:17:53 Re: Assigning password to the superuser
Previous Message Justin Hawkins 2005-04-15 03:58:45 Assigning password to the superuser