public inbox for [email protected]
help / color / mirror / Atom feedFrom: David G. Johnston <[email protected]>
To: Mauricio Fernandez <[email protected]>
Cc: Pgsql-admin <[email protected]>
Subject: Re: Script generation through psql
Date: Wed, 22 Oct 2025 06:54:13 -0400
Message-ID: <CAKFQuwbL+S0kQiSPt_SzXbOYf8FtrPLLTnUUHq_y1ooyXOffDQ@mail.gmail.com> (raw)
In-Reply-To: <CAMdfv4XRZXZmZm3NWmjPe69kaAnkRTX_8Jq1qp+Pet9mD4eCaw@mail.gmail.com>
References: <CAMdfv4XRZXZmZm3NWmjPe69kaAnkRTX_8Jq1qp+Pet9mD4eCaw@mail.gmail.com>
On Tuesday, October 21, 2025, Mauricio Fernandez <
[email protected]> 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’d have to do something like:
Execute format(‘set script.varname=%L’, value)
Within the DO block then you can do:
Select current_value(‘script.varname’) as psql_var \gexec
Outside of it.
A temporary table works too.
David J.
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: Script generation through psql
In-Reply-To: <CAKFQuwbL+S0kQiSPt_SzXbOYf8FtrPLLTnUUHq_y1ooyXOffDQ@mail.gmail.com>
* 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