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 1vBXYk-000Je9-KP for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 12:03: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 1vBXYj-00Fq7k-Id for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 12:03:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vBXYj-00Fq7c-6N for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 12:03:16 +0000 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBXYf-003btR-38 for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 12:03:15 +0000 Received: by mail-ua1-x92e.google.com with SMTP id a1e0cc1a2514c-8e352f6c277so1619149241.2 for ; Wed, 22 Oct 2025 05:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761134591; x=1761739391; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=v3R02zyuaBcEDN7y9xUP2+PpVoTXAzIndOpqUpTU8Ls=; b=Rfm2LnRV0deCk5MsV8awyrNFqImuo4BisF7sNielOY3Zq/IDxQUIzLs6cdPefJEkGU vAlwwcN5EG3w2wz1MYrZ9pAobm44M2AtZp/vrnG81Iz2wMD5tepeBb0Ku9t4LbMQWzYz 5jRNWLqSWY0ggV7jV7kF3LZR9MPdIEW2ueBC0Mi1g+UyKIxmmN9BVnDJER3wxAG2qTTD 3gB2CWkpCY+qqVm5+WcCkipD9wLecNKByXx8NXLjU4I/knRBM3miVEALLrbHjnOxaWvr Kb/iezUt5+61lhqnyEss8L58t4712kIVFpDszPfu3I97NoyDusxUICQCcZOaHLxza2iH Vy5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761134591; x=1761739391; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v3R02zyuaBcEDN7y9xUP2+PpVoTXAzIndOpqUpTU8Ls=; b=f0sBECKKGwgN/H4GIZJfcSe5l3UGQ+++skEKYLw3MKqZv+BDx0imgrNNenonuam2Vz fNLeKsTbrujtGXHkETWJddZkJbAQYCjwYZFx5+4r0SbFycpCs/6oxKT3YsJx7PwcsEJC 3AbteTirxzlFfk884MYJjrUhGJOl/bkN/69azdXmcLMX1Bzguf2YhY3dJ2RqqtKt3qcE qwkrcjBmufkuLXEsFMv+Y6SoJoDPp7UQuZK8hrYARdH95m+uD06UO5mxWX1JotacK3Hm L7RVzc2E+o2QM2AXLBx/CotO2PiHPgmQrLz/TmdKcBh2XsWVOiwP4Wj+9e6qYFnLtNvZ 79Qg== X-Gm-Message-State: AOJu0YzfgD0novdZTayspXfZLo+60AbW8bxQXqLREXDqUgPd+EhZyG9Y muYhoDvD9+2CPtN7Bw7Ozu3XMYNWoKdFqVY4M2a2M0vCsFTgiAydnxsm6dFQPkTlGVxlrPLoxW8 m+jV23Q5A1+BAIwYhp6ZA/0gXW/SpzL5y2Tj3 X-Gm-Gg: ASbGncuUw4NOWWy7YSYkWUj+HVt7oS9e3jVHdxyGuGYT5HmAxI/9spqdD2tcPs7KvYK 9fAeldEiZ+o5woaufZuqoKAhU6AWpqIADxRN8k049532GePrFfFp7EJ4eWF9xN2Dwc+Eb9aebxi JTyG+7zJ77fZ25gZWa3qN8NVkkRewmBBZHZM9Farz82shOhDGnfdhQNiLPZPU8HZcMkrKa2fO6p Yo6oUw6lyPpJR2sLqXkh53ZjHgCaXrqM+bkCq+S8VISncdNjZTld9OrcW1qqexJtvPBkPd4iPfX tJzfHfa+Ngy5Zbfhx5uGEgacPJ2snusJBPB5jA== X-Google-Smtp-Source: AGHT+IG6SJvCMQdNxkT5T4S277REVxRzl7RiewKB/6nn1Xr8fpCWLJ0eSF2+Sz8Jd4N1eZc3EEJp6BpAYE7keetGqwU= X-Received: by 2002:a05:6102:2926:b0:5d5:f6ae:38c1 with SMTP id ada2fe7eead31-5d7dd70853bmr5916984137.42.1761134591537; Wed, 22 Oct 2025 05:03:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Mauricio Fernandez Date: Wed, 22 Oct 2025 09:03:00 -0300 X-Gm-Features: AS18NWCaOqLKGzcVFs4hSsKXfxl2po2xDfcCRzTpDCdQwsqTdzpy-zcOS0KbzhM Message-ID: Subject: Re: Script generation through psql To: =?UTF-8?Q?Roland_M=C3=BCller?= Cc: Pgsql-admin Content-Type: multipart/alternative; boundary="000000000000baf3a30641be19da" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000baf3a30641be19da Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=3D"" the desired output was as expected export PAGER=3D"" psql *-Atq* -U moodle -d lms4x -f ./src.sql > $UPD_FILE 2>&1 regards Mauricio Fern=C3=A1ndez El mi=C3=A9, 22 oct 2025 a las 1:23, Roland M=C3=BCller (= ) escribi=C3=B3: > 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 ezt =C3=ADrta (id=C5= =91pont: > 2025. okt. 21., K 23:52): > >> Hi community >> >> I'm trying to generate an script file as the output from psql script bee= n >> 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 =3D :vl_id; >> >> select script_import from proceso_actualiza_fdw where id =3D :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 anonymou= s >> 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 =3D :*vl_id*; >> >> select script_import from proceso_actualiza_fdw where id =3D :*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=C3=A1ndez >> > --000000000000baf3a30641be19da Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Roland, thanks=C2=A0for 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=3D"" t= he desired output was as expected

export PAGER=3D&= quot;"
psql -Atq -U moodle -d lms4x -f ./src.sql > $UPD_F= ILE 2>&1

regards Mauricio Fern=C3=A1n= dez

El mi=C3=A9, 22 oct 2025 a las 1:23, Roland = M=C3=BCller (<rolmur@gmail.com&g= t;) escribi=C3=B3:
Hello,

th= e \copy command should be able to output only the results of some=C2=A0 que= ry. This command is=C2=A0 client side. Thus \copy runs in psql and uses the= server side COPY .


BR
Roland=C2=A0


Mauricio Fernandez <mmauricio.= fernandez@gmail.com> ezt =C3=ADrta (id=C5=91pont: 2025. okt. 21., K = 23:52):
Hi community=C2=A0

I'm trying to generate a= n script file as the output from psql script been called from linux bash, a= nd 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
\se= t ECHO none
\pset tuples_only on
\pset pager off

select script= _drop from proceso_actualiza_fdw where id =3D :vl_id;

select script_= import from proceso_actualiza_fdw where id =3D :vl_id;

\q
=
1.- The output=C2=A0file is like :
Pager usage = is off.
=C2=A0-- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+
=C2=A0-- BORRADO DE TABLAS MO= DIFICADAS =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+
<= br>
How can I eliminate "Pager usage is off." an= d the "+"=C2=A0 at the end of each row?

2. If in the psql script I want to pass variable values from an anon= ymous block to the rest of the script,=C2=A0how can=C2=A0I proceed?. For ex= ample

DO $$
DECLARE
=C2=A0 vl_id integer;BEGIN
=C2=A0-- vl_id is set inside the procedure
=C2=A0 call my_proc= edure(vl_id);
END $$;

select script_drop= from proceso_actualiza_fdw where id =3D :vl_id;

select scrip= t_import from proceso_actualiza_fdw where id =3D :vl_id;
<= br>
The script output file is the result set=C2=A0from the querie= s.

I've tried=C2=A0with \set myvar but this do= esn't works

Thank you very much in advance

kind regards

Mauricio Fern= =C3=A1ndez
--000000000000baf3a30641be19da--