Re: Script generation through psql

From: Roland Müller <rolmur(at)gmail(dot)com>
To: Mauricio Fernandez <mmauricio(dot)fernandez(at)gmail(dot)com>, Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Script generation through psql
Date: 2025-10-22 04:23:45
Message-ID: CA+8p0G1pG-x02FfUnK=jOQzCHYGstxdbBPvDGRfprDr8sYY_tQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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://stream.boxwatch.ru/docs/17/app-psql.html

BR
Roland

Mauricio Fernandez <mmauricio(dot)fernandez(at)gmail(dot)com> 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
>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2025-10-22 10:54:13 Re: Script generation through psql
Previous Message Laurenz Albe 2025-10-22 03:57:51 Re: Script generation through psql