Re: Script generation through psql

From: Mauricio Fernandez <mmauricio(dot)fernandez(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Script generation through psql
Date: 2025-10-22 12:45:18
Message-ID: CAMdfv4VJiDXnD_=ngHh-3yUrT4K+8qA1_FVEVOy=smMg8Ri-sQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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 = :x_id;

select script_import from proceso_actualiza_fdw where id = :x_id;

\q

The procedure declaration is: actualiza_fdw(OUT x_id integer)

regards

Mauricio Fernández

El mié, 22 oct 2025 a las 7:54, David G. Johnston (<
david(dot)g(dot)johnston(at)gmail(dot)com>) escribió:

> On Tuesday, October 21, 2025, Mauricio Fernandez <
> mmauricio(dot)fernandez(at)gmail(dot)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’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.
>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2025-10-22 14:26:33 Re: does BUG #18942 and BUG #18938 solution available in Pg16 latest release 16.10
Previous Message Mauricio Fernandez 2025-10-22 12:43:22 Re: Script generation through psql