From: Alvaro Herrera <alvherre@commandprompt.com>
To: Jorge Godoy <jgodoy@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Creating nested functions with plpgsql
Date: Sun, 7 May 2006 19:33:43 -0400
Message-ID: <20060507233343.GC31301@surnet.cl> (raw)
In-Reply-To: <200605021414.49661.jgodoy@gmail.com>
References: <200605021414.49661.jgodoy@gmail.com>
Jorge Godoy wrote:
> I have some real case examples where this could be useful, if it is needed.
> I haven't pasted them here because the smallest one has 176 LOC, after
> refactoring with nested functions.
>
> If it is not possible, are there any plans to allow this kind of thing?
> (Even with a different syntax it would be good to have it.)
We don't support nested functions at present, but you can create a
separate function and invoke it as you would call any external function.
This is arguably better, because you may then use inner_function in any
"outer function", not just the current one.
Something like:
CREATE FUNCTION inner_function(OUT output_day DATE) AS $_$
DECLARE
output_day DATE;
BEGIN
-- do something to calculate output_day
RETURN output_day;
END
$_$;
CREATE FUNCTION outer_function(param1 DATE) RETURNS date AS $$
DECLARE
output_day DATE;
BEGIN;
output_day = SELECT inner_function(params_to_create_date);
-- do something in main function that uses inner function several
-- times.
END;
$$ language plpgsql;
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: alvherre@commandprompt.com, jgodoy@gmail.com
Subject: Re: Creating nested functions with plpgsql
In-Reply-To: <20060507233343.GC31301@surnet.cl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox