Re: syntax question - Mailing list pgsql-general

From Tom Lane
Subject Re: syntax question
Date
Msg-id 49061.1622748075@sss.pgh.pa.us
Whole thread Raw
In response to Re: syntax question  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: syntax question  (Bruce Momjian <bruce@momjian.us>)
Re: syntax question  (Marc Millas <marc.millas@mokadb.com>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: syntax question
Next
From: Vijaykumar Jain
Date:
Subject: Re: max_connections