public inbox for [email protected]  
help / color / mirror / Atom feed
From: Mauricio Fernandez <[email protected]>
To: Roland Müller <[email protected]>
Cc: Pgsql-admin <[email protected]>
Subject: Re: Script generation through psql
Date: Wed, 22 Oct 2025 09:03:00 -0300
Message-ID: <CAMdfv4XctGzubbgkASHRdDG1jMjwRrOesQpYJczACdcTingrTw@mail.gmail.com> (raw)
In-Reply-To: <CA+8p0G1pG-x02FfUnK=jOQzCHYGstxdbBPvDGRfprDr8sYY_tQ@mail.gmail.com>
References: <CAMdfv4XRZXZmZm3NWmjPe69kaAnkRTX_8Jq1qp+Pet9mD4eCaw@mail.gmail.com>
	<CA+8p0G1pG-x02FfUnK=jOQzCHYGstxdbBPvDGRfprDr8sYY_tQ@mail.gmail.com>

Hi Roland, thanks for the answer, I will investigates de \copy command. For
know, I could resolve with the following call in the bash script:

Using -Atq and PAGER="" the desired output was as expected

export PAGER=""
psql *-Atq* -U moodle -d lms4x -f ./src.sql > $UPD_FILE 2>&1

regards Mauricio Fernández

El mié, 22 oct 2025 a las 1:23, Roland Müller (<[email protected]>) escribió:

> Hello,
>
> the \copy command should be able to output only the results of some
> query. This command is  client side. Thus \copy runs in psql and uses the
> server side COPY .
>
> https://www.postgresql.org/docs/17/app-psql.html
>
> BR
> Roland
>
>
> Mauricio Fernandez <[email protected]> ezt írta (időpont:
> 2025. okt. 21., K 23:52):
>
>> Hi community
>>
>> I'm trying to generate an script file as the output from psql script been
>> called from linux bash, and I've two issues:
>>
>> The bash call is like:
>>
>> psql -U myusr-d mydb -f ./scr.sql > $UPD_FILE 2>&1
>>
>> $ cat scr.sql
>> \set vl_id 19
>> \set ECHO none
>> \pset tuples_only on
>> \pset pager off
>>
>> select script_drop from proceso_actualiza_fdw where id = :vl_id;
>>
>> select script_import from proceso_actualiza_fdw where id = :vl_id;
>>
>> \q
>>
>> 1.- The output file is like :
>> *Pager usage is off.*
>>  --                                                                  *+*
>>  -- BORRADO DE TABLAS MODIFICADAS                                    +
>>
>> How can I eliminate "*Pager usage is off." *and the *"+"  *at the end of
>> each row?
>>
>> 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 $$;
>>
>> select script_drop from proceso_actualiza_fdw where id = :*vl_id*;
>>
>> select script_import from proceso_actualiza_fdw where id = :*vl_id*;
>>
>> The script output file is the result set from the queries.
>>
>> I've tried with \set myvar but this doesn't works
>>
>> Thank you very much in advance
>>
>> kind regards
>>
>> Mauricio Fernández
>>
>


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: <CAMdfv4XctGzubbgkASHRdDG1jMjwRrOesQpYJczACdcTingrTw@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