public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: Dirschel, Steve <[email protected]>
To: [email protected] <[email protected]>
Subject: Re: Trying to dynamically create a procedure
Date: Fri, 28 Mar 2025 08:12:32 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CH0PR03MB6034C83799B64677E3D4941AFAA62@CH0PR03MB6034.namprd03.prod.outlook.com>
References: <CALdEsqOM2q7bXt1Bo2S_41nHgSjR2_epzm=aHHFoHsQdzB3fqQ@mail.gmail.com>
	<CH0PR03MB6034C83799B64677E3D4941AFAA62@CH0PR03MB6034.namprd03.prod.outlook.com>

On Wed, 2025-03-26 at 20:27 +0000, Dirschel, Steve wrote:
> DO $$
>  
> BEGIN
>  
> EXECUTE 'create or replace procedure junk.test_proc() ' ||
>   'LANGUAGE plpgsql  '                          ||
>   'AS $$ '                            ||
>   'declare  '                              ||
>   '  v_cnt         integer := 0; '               ||
>   'begin '                            ||
>   '  raise notice 'v_cnt is %', v_cnt; '         ||        
>   'end $$';
>  
> END;
>  
> $$
>  
> It throws this error:
>  
> ERROR:  syntax error at or near "$$
> DO $$"
> LINE 1: $$
>         ^
> dbtest=>
> dbtest=> END;
> WARNING:  there is no transaction in progress
> COMMIT

If you nest dollar quotes, you need to use different strings between the dollars:

DO $do$
BEGIN
   EXECUTE 'CREATE PROCEDURE ... AS $fun$ ... $fun$';
END;
$do$;

Yours,
Laurenz Albe


view thread (3+ messages)

reply

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: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Trying to dynamically create a procedure
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox