From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Marc Millas <marc.millas@mokadb.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: syntax question
Date: Thu, 3 Jun 2021 15:34:44 -0400
Message-ID: <20210603193444.GD22019@momjian.us> (raw)
In-Reply-To: <49061.1622748075@sss.pgh.pa.us>
References: <CADX_1aa=8woWOoOzo0iMjvkFkJC1=31+fziMaAUfFu4u7d0_xg@mail.gmail.com>
<20210603190108.GC22019@momjian.us>
<c58b04ac-e713-f089-8400-763a742bf86d@aklaver.com>
<49061.1622748075@sss.pgh.pa.us>
On Thu, Jun 3, 2021 at 03:21:15PM -0400, Tom Lane wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 6/3/21 12:01 PM, Bruce Momjian wrote:
> >> On Thu, Jun 3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
> >>> within a function, I want to create another function.
>
> >> You can't create functions inside of functions; same for procedures.
>
> > Sure you can:
>
> Yeah. The actual problem here is that Marc is expecting variable
> substitution to occur within a utility (DDL) statement, which it
> doesn't. The workaround is to build the command as a string and
> use EXECUTE, as Adrian illustrated:
>
> > EXECUTE 'create function ' || bidule || '() RETURNS void language
> > plpgsql AS $fnc$ BEGIN END; $fnc$ ';
>
> This is not terribly well explained in the existing docs. I tried
> to improve the explanation awhile ago in HEAD:
>
> https://www.postgresql.org/docs/devel/plpgsql-statements.html#PLPGSQL-STATEMENTS-GENERAL-SQL
Oh, I thought he wanted to declare a function inside the function that
could be called only by that function, like private functions in Oracle
packages can do. Yes, you can create a function that defines a function
that can be called later. I guess you could also create a function that
_conditionally_ creates a function that it can call itself too. My
point is that you can't create a function that has function scope ---
they all have schema scope.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, marc.millas@mokadb.com
Subject: Re: syntax question
In-Reply-To: <20210603193444.GD22019@momjian.us>
References: <CADX_1aa=8woWOoOzo0iMjvkFkJC1=31+fziMaAUfFu4u7d0_xg@mail.gmail.com> <20210603190108.GC22019@momjian.us> <c58b04ac-e713-f089-8400-763a742bf86d@aklaver.com> <49061.1622748075@sss.pgh.pa.us> <20210603193444.GD22019@momjian.us>
* 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