From: Jorge Godoy <jgodoy@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Creating nested functions with plpgsql
Date: Tue, 2 May 2006 14:14:48 -0300
Message-ID: <200605021414.49661.jgodoy@gmail.com> (raw)
Hi!
Is it possible to create nested functions using plpgsql as the language? I'd
like to avoid other dependencies if I can, besides using already written SQL
code...
There are lots of repetitive tasks that "subfunctions" would solve in a very
elegant way, keeping code more readable and concise.
I was thinking something along the lines of:
CREATE FUNCTION outer_function(param1 DATE) RETURNS date AS $$
DECLARE
BEGIN
CREATE FUNCTION inner_function(OUT output_day DATE) AS $_$
DECLARE
output_day DATE;
BEGIN
-- do something to calculate output_day
END;
$_$ language plpgsql stable strict;
-- here I could have other languages or
-- even restrict the inner function to the
-- same language as the outer function...
-- $_$ is different from $$ intentionally.
-- do something in main function that uses inner function several
-- times.
END;
$$ language plpgsql;
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.)
TIA,
--
Jorge Godoy <jgodoy@gmail.com>
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: jgodoy@gmail.com
Subject: Re: Creating nested functions with plpgsql
In-Reply-To: <200605021414.49661.jgodoy@gmail.com>
* 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