Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vBYDd-000RnO-Jj for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 12:45:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vBYDc-00GHMs-Jk for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 12:45:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vBYDc-00GHMj-4W for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 12:45:31 +0000 Received: from mail-vs1-xe2a.google.com ([2607:f8b0:4864:20::e2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBYDZ-0039yn-1D for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 12:45:30 +0000 Received: by mail-vs1-xe2a.google.com with SMTP id ada2fe7eead31-5a3511312d6so3417924137.3 for ; Wed, 22 Oct 2025 05:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761137128; x=1761741928; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MQRv4/lgn1DE0sZbKaVtOxD4yhj6zjnmq5pfC0m8wJs=; b=Wg8qU9Q6CfUEmdXA+U2n8NZs3aNLmECnMnZOk+gJ33lG7TwQ5K1+O+2MDKKYIgVfpe o5GcemhsEaNf+jrz8tB9GNKupryDTQ/rC8INH8fEUQ3NO0Wk8GHTlnv6S9pMJahd04TQ X8Srcubf2i2oWEHh6b2h8fw+I3euNtQmEMQvZNNOfNffipazJWdTo3XxFvgpbcm114V3 lNbgFlLyh0cw6ROFAIqpv5++98i6JIHHgFZ7YyySuAn+SZq6sedBLEFmNIYRZ/OeBXVI w0uzoBDCR9f2928CIkirRDMyKYL1inIRLoVpa5bMmIB2g34kWmgBWLzUzzrgE9vaCmx9 ioiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761137128; x=1761741928; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MQRv4/lgn1DE0sZbKaVtOxD4yhj6zjnmq5pfC0m8wJs=; b=QtfRHthcn6xzVq/eGFB+nrXwhiz9x6ow8s+hWPG8DkP21wg6WB4OfZgZ5ZEq0iyZ+h iTeTQA+jZbszCgaxVTpxN3md19IhE8eZBxe5idAvw/8JgUhHe6DXxSTazX2uTjd9kEG4 vd3Xz/QTPQNH+pBWOnwPC/olRLG9NEWJEmL2SggyoNRmzcOUFdbzQE3P+RwvKnYv4ZPe 0GMVEpB7E5JCN7DMISdf1zrD7EkUnLlKHkQsQvp3zJB94N89xwGL393qB63awfB+5D0b N52m21jy3uWu9mtOtphD02icLqjpDUpHlhVE2sTu8RAIoc2D0/BdmHr5CtIKBsYzBz91 Wt1A== X-Gm-Message-State: AOJu0YzC9aSkUGxY2TQfFfjL9zWcxXx24Tga7MqnSvtvJbiGYqieatT7 wqQ25dCywo4gqPQL/AioC5T8HECd4VSMUnwkIhZj3bfBc7Tcn4HyE26HKIBhuHtZtx+M7sc6v64 VYWmxMnf4zHxgHbpkDTPfzVQ0xWZ+vc4= X-Gm-Gg: ASbGncvuWP7ulue8UttUIMvtjr9jKhUQCQN8SUetgfUa84Bp5FaOBL8JTBFGHD5eMrX gfOSSHzgjdau2cD0YwAcTzVJP/cmY7Fx8PeqHo3R2GTv9pGNdfiKTVFOuWG+KhgABFw0ejXDYXm DF7h08e2yObHfnDyxrWIX+gaZSfkww/lJC+USFvoEr2xpXMM+6knbXpF/O1DptvyaZf2/dIbO8q l52lHOtAFUmuSRJTV5Djj7MiO4sysHa8quakW4pB1Sh0CK7/Sp70PAIHCrxF2CTTJ7N4tRBP//a F8hUzbWNljU0DI+ThxD0ogni+hKLO5QaotQUkw== X-Google-Smtp-Source: AGHT+IGl3F9tEhdlZPREY6/6Cu7515NgJ69wdbZRDn9xCoZcYI75cCD3sbxHe9kbb9aI+8volgVoW8MTa6v+ew+1dbo= X-Received: by 2002:a05:6102:3f49:b0:5d6:615:a687 with SMTP id ada2fe7eead31-5d7dd5544d6mr6055357137.7.1761137128349; Wed, 22 Oct 2025 05:45:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Mauricio Fernandez Date: Wed, 22 Oct 2025 09:45:18 -0300 X-Gm-Features: AS18NWCygrCNRdnK828OLWr67bJfiWkFLTMOJLbHHlPwxd7cN88BWq9Xt72zwbM Message-ID: Subject: Re: Script generation through psql To: "David G. Johnston" Cc: Pgsql-admin Content-Type: multipart/alternative; boundary="000000000000efa47f0641beb0fd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000efa47f0641beb0fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi David, thanks for answer..I could resolve my issue doing the following in the script call actualiza_fdw(null) ;\gset select script_drop from proceso_actualiza_fdw where id =3D :x_id; select script_import from proceso_actualiza_fdw where id =3D :x_id; \q The procedure declaration is: actualiza_fdw(OUT x_id integer) regards Mauricio Fern=C3=A1ndez El mi=C3=A9, 22 oct 2025 a las 7:54, David G. Johnston (< david.g.johnston@gmail.com>) escribi=C3=B3: > On Tuesday, October 21, 2025, Mauricio Fernandez < > mmauricio.fernandez@gmail.com> wrote: >> >> >> 2. If in the psql script I want to pass variable values from an anonymou= s >> block to the rest of the script, how can I proceed?. For example >> >> DO $$ >> DECLARE >> vl_id integer; >> BEGIN >> -- vl_id is set inside the procedure >> call my_procedure(*vl_id*); >> END $$; >> > > You=E2=80=99d have to do something like: > > Execute format(=E2=80=98set script.varname=3D%L=E2=80=99, value) > > Within the DO block then you can do: > > Select current_value(=E2=80=98script.varname=E2=80=99) as psql_var \gexec > > Outside of it. > > A temporary table works too. > > David J. > > --000000000000efa47f0641beb0fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi David, thanks for answer..I could resolve my issue doin= g the following in the script

call actualiza_fdw(null) ;= \gset

select script_drop from proceso_actualiza_fdw where id =3D :x_= id;

select script_import from proceso_actualiza_fdw where id =3D :x_= id;

\q

The procedure declaration is:=C2=A0actualiza_fdw(OUT x_id integer)

regards

Mauricio Fern=C3=A1ndez
=

El mi=C3=A9, 22 oct 2025 a las 7:54, David G. Johnsto= n (<david.g.johnston@gmail= .com>) escribi=C3=B3:
On Tuesday, October 21, 2025, Mauricio Fernandez <mmauricio.ferna= ndez@gmail.com> wrote:

2. If in the psql script I wa= nt to pass variable values from an anonymous block to the rest of the scrip= t,=C2=A0how can=C2=A0I proceed?. For example

DO $$=
DECLARE
=C2=A0 vl_id integer;
BEGIN
=C2=A0-- vl_id is set insi= de the procedure
=C2=A0 call my_procedure(vl_id);
END $$;

You=E2=80=99d have to do some= thing like:

Execute format(=E2=80=98set script.var= name=3D%L=E2=80=99, value)

Within the DO block the= n you can do:

Select current_value(=E2=80=98script= .varname=E2=80=99) as psql_var \gexec

Outside of i= t.

A temporary table works too.

David J.

--000000000000efa47f0641beb0fd--