From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: Marc Millas <marc.millas@mokadb.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: syntax question
Date: Thu, 03 Jun 2021 15:21:15 -0400
Message-ID: <49061.1622748075@sss.pgh.pa.us> (raw)
In-Reply-To: <c58b04ac-e713-f089-8400-763a742bf86d@aklaver.com>
References: <CADX_1aa=8woWOoOzo0iMjvkFkJC1=31+fziMaAUfFu4u7d0_xg@mail.gmail.com>
<20210603190108.GC22019@momjian.us>
<c58b04ac-e713-f089-8400-763a742bf86d@aklaver.com>
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
regards, tom lane
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: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, bruce@momjian.us, marc.millas@mokadb.com
Subject: Re: syntax question
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>
* 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