Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1losuB-00010E-Q9 for pgsql-general@arkaria.postgresql.org; Thu, 03 Jun 2021 19:21:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1losuA-0005wO-P8 for pgsql-general@arkaria.postgresql.org; Thu, 03 Jun 2021 19:21:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1losuA-0005wG-GB for pgsql-general@lists.postgresql.org; Thu, 03 Jun 2021 19:21:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1losu7-00076o-U7 for pgsql-general@lists.postgresql.org; Thu, 03 Jun 2021 19:21:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 153JLF7c049062; Thu, 3 Jun 2021 15:21:15 -0400 From: Tom Lane To: Adrian Klaver cc: Bruce Momjian , Marc Millas , "pgsql-general@lists.postgresql.org" Subject: Re: syntax question In-reply-to: References: <20210603190108.GC22019@momjian.us> Comments: In-reply-to Adrian Klaver message dated "Thu, 03 Jun 2021 12:11:00 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <49060.1622748075.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Jun 2021 15:21:15 -0400 Message-ID: <49061.1622748075@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver 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-STAT= EMENTS-GENERAL-SQL regards, tom lane