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 1vBWTz-00057i-9R for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 10:54:18 +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 1vBWTx-00FM5h-OV for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 10:54:16 +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 1vBWTx-00FM5T-BL for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 10:54:16 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBWTu-00390P-2N for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 10:54:15 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7c290b18a76so2723395a34.1 for ; Wed, 22 Oct 2025 03:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761130454; x=1761735254; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SJ2gQNimkoQSjCgin+EamC15ciffhF5jgak75OLcDoI=; b=FMbrTYWLS7DQyqsF2KK4z9WOUIC4ehlejyGAllRud6nxonOdw6Das934Yza+6Uy3DR Cug37VHvwq3XME70vFvxNGYzSbwNTvNDwEaNGvNF6THh5xeopD3DR3uAXTNarkTVRHSy d4zauhRkzTbhem3rw8QtrBY+pyXEw8MEgfz/M5UchBKIHtUBjNyKgcZvegyfjMxikql0 FUHJVLYaYG+aX9cUdPopSaEA0qzbxC1ay5dbJstFGCkPi9/vTNJ25rrIWq0PJMlbaJ7g U7iEXaJsqLMLb0PwBpH/tYZVVHmeYXTBmh1qnxzNZuv0HAo8QTaIlASnd878txhI/jrB WOKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761130454; x=1761735254; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SJ2gQNimkoQSjCgin+EamC15ciffhF5jgak75OLcDoI=; b=F17zr1Vwfes9EtN1xgoIBgtAAAffOMxbo8Xx8JyFUUz3xURtmFnzvH1xMmC/z6B4UJ V9GaEce3LAs4QolCAqKhUm0T645k6x/0VROfWpl9Hbt9zuggHNp1HsexncARVx9kn4gl YHXf9MZ7hk9VNzDyDa3RsWLqTd5EgZ7iFXAN8NnLqbh2CgDRI9c4bP+7/KeECwE5Tucm sdlrTeG6GB/JadFBLaCc0bC7ItDUpt833OhVAuLNBZIErXqkyNgvk//+UUJ0cuBox0C+ znUEGSiP8qYJu81xmBzSz4MOZol5FoQZg+/enuQ5DxtNnwgIhE8AkkMfv9Amx9XDGvZs IAbw== X-Gm-Message-State: AOJu0YzUuLjRuE7uHa4WmwHHXQE3rOtCCw0ADEZwcqLuUCd9hrCskcJ6 x9Mngfs6rrRvmdhlXIlMy2QSsghLkfQHWxDOYHv+1nuUC4tyU6Yb2K07zLlCrgYZgunVAGF5Qku bxfa9aM8osVflkMsGKgDmqKhLRGS5fkU= X-Gm-Gg: ASbGnctBmCEeYPA+n6VMlT/K7fqtB0bLoYMRX/afOL7EoWUK2abTjyqGR4YTE6L6lri q3OW4+OE+nYQgCc/A4WH45weS46G9StYolnIqV5J1W6yrS+t+jLNHksfk0bXcdLAFWwaImKJq08 pDgZDXeFDdc5o1QcHQDqQdu0rrrTay780Ped1OOQtc9juVSOvenfmRJ+/Vxq7TJ95hCH7n5PbKq 7lHgDULLRToqwPPMWFyjbqeYdkQCrhobMkysUNSbUjPiGZLlJ6KTnWPyj0= X-Google-Smtp-Source: AGHT+IHJvXCQPkPUlbJD6WZHxal9mADojjorKe181QeJzpe/U+Dx6Ys9PeDSboGrITc4VLVQ94T9+Kv8I64hazabTgE= X-Received: by 2002:a05:6808:3a0b:b0:43f:47ba:6a7f with SMTP id 5614622812f47-443a3095638mr8180355b6e.31.1761130453797; Wed, 22 Oct 2025 03:54:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:7444:0:b0:5f3:5bf6:6b0b with HTTP; Wed, 22 Oct 2025 03:54:13 -0700 (PDT) In-Reply-To: References: From: "David G. Johnston" Date: Wed, 22 Oct 2025 06:54:13 -0400 X-Gm-Features: AS18NWAqed6OyrWy3Hj5TMXD1RHt7NaEzMkC8sanU8bbnAbOPAVXIPcNN505M1A Message-ID: Subject: Re: Script generation through psql To: Mauricio Fernandez Cc: Pgsql-admin Content-Type: multipart/alternative; boundary="0000000000001a11d30641bd23fc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001a11d30641bd23fc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 anonymous > 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. --0000000000001a11d30641bd23fc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 anonymous block t= o the rest of the script,=C2=A0how can=C2=A0I proceed?. For example

DO $$
DECLARE
=C2=A0 vl_id integer;
BEGIN
=C2= =A0-- vl_id is set inside the procedure
=C2=A0 call my_procedure(vl_i= d);
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 curren= t_value(=E2=80=98script.varname=E2=80=99) as psql_var \gexec

=
Outside of it.

A temporary table works = too.

David J.

--0000000000001a11d30641bd23fc--