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 1vBPz4-00GIUe-Sa for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 03:57:58 +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 1vBPz3-00D9El-QY for pgsql-admin@arkaria.postgresql.org; Wed, 22 Oct 2025 03:57:56 +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 1vBPz3-00D9EF-EM for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 03:57:56 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBPz0-003Xxx-0b for pgsql-admin@lists.postgresql.org; Wed, 22 Oct 2025 03:57:56 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-57b8fc6097fso5874804e87.1 for ; Tue, 21 Oct 2025 20:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1761105473; x=1761710273; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=k/IPuQr8n6XZyuwpzYB4AqatFB/ePbqYP6NOm899jkY=; b=Y3/Mtv1pX8vwWbzKzT7yw8ufn46W+uNdJxjDILZuHKzozXGT/cHITjbIOs5m0Ed4YO JqrrZ5zm8RyiuPNxauZuBz4oI3OAtU6MquK8cSM2Qvibe2JIGg1lfxVkDnHYr0VyF/E8 ZUXAAVg7zHYbXRsSRfamDcKgnNtc5VRUiQ48aCL04gjSTFj68KwJvps62slAfQKX35uj enIBoMrNm8I3dT0p8M0SbzvjcJGz3yhIKeJrTtNRxjIDZPYLQYiYcsTsHAv3+GEhWMbL KKWV6q4IMTQFH1bCWOLaLWXJc2t98eadM5C0aPJxSzdY8f3MBYYRaqcHvYV8QUtiHHiP 5sFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761105473; x=1761710273; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=k/IPuQr8n6XZyuwpzYB4AqatFB/ePbqYP6NOm899jkY=; b=ClfxmP8FRoi4sqKM88qcKPoUycjRMDDyJZdHskwXQsGP+nMNZJPtTJJN9UYHJt0/WD dchQF8mTr/ZtKKwvzKU0liBFGt+LzEE44b+SA7QiDRtVOPFrpgwkhAx6m+mJkUdRFB5o +jb3Lrxte2Ehy17mxoo59G0Mq3uP1pTNKf1+vXmDpcMkZ9bqdeOXF7aEyUo6+A7AzDl5 JoPZIvDyhgUPbNp9iTbmi2PhPGmEbjExthPG4WboqGHUdoL5xanEROjeAGt4zo1rsXwa 71Mr0Y/hy02n0pQI9MhCpgGWORTyj9ymh6U8coMWW5d/6ObjpETZaAX9d/GFKLQqVbyX dFaQ== X-Forwarded-Encrypted: i=1; AJvYcCVdmS2sUXYSqrvoVIJtvQa5uOyCdHrTG2es/86g9eoIvMu8a7sOnBrKe/10D/dcc8SCHGMoowqKbky9dw==@lists.postgresql.org X-Gm-Message-State: AOJu0YwWe+CUuJcMgZ3wwJw+UnLwaA7WnDTwx6LXi+wIvNNhLjxMPpb/ qvUChhQbYLgvWNH8SKqfenKPe6Op8QavXMM6ZFr8hd7nNTvJjqD5v2AYpEtX3frsq94= X-Gm-Gg: ASbGnctBssIpQAY/SRwMVI4vZjfuux5NKmT1aicaI76z1uUhGJg5lWDR/gBHYyCP1y7 TrzzdZM8AwnV+jNfkUbW9Lfq3yRBKwv4zIKFENVv3p+X0KTEO39vuyMFjaJciLJocC5OtkDb1bv v7NAwb2yU5WTxfTa7hcR2DPC89Zva/h2UjrUhEYtj1Jq+A0+gvWlIzPe6lZxTJoKhokGSnyQXO7 bP756IBDyMDZ3wv7i9BukFShs6mG0L3qTAO/++A5Fk6ZO9hyoNu2wPq8aMD1wAQipzpsBOk2r9D bIj+jNQqa+MDq+OToTfIbQ+bY1TRQtvCIt7AvA6kxdRLUvvIhXdZidHZ3vC5sxVDsS7AxpBSshi BuvDnpv6/lL6Nkn92mEStidGjJExd/9ratgS6t0MVyLbF6okS+UZ+CGDrHR+vA6znhV8nXdWVgr 9Aa7tY8NTwNzbksTGFrnhjRDHSUW/FrcQ= X-Google-Smtp-Source: AGHT+IGSciipl81qusdVJLrnSHTZ3X9ubWNcErTYWhyudLX0UZa/X4L5l4BkqcHephMp+vCSwID0bg== X-Received: by 2002:a05:6512:61cc:20b0:591:eb9d:ac01 with SMTP id 2adb3069b0e04-591eb9dafbbmr1162169e87.41.1761105473000; Tue, 21 Oct 2025 20:57:53 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([159.148.223.130]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-591def16a91sm4202947e87.69.2025.10.21.20.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 20:57:52 -0700 (PDT) Message-ID: Subject: Re: Script generation through psql From: Laurenz Albe To: Mauricio Fernandez , Pgsql-admin Date: Wed, 22 Oct 2025 06:57:51 +0300 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-10-21 at 17:51 -0300, Mauricio Fernandez wrote: > I'm trying to generate an script file as the output from psql script been= called from linux bash, and I've two issues: >=20 > The bash call is like: >=20 > psql -U myusr-d mydb -f ./scr.sql > $UPD_FILE 2>&1 >=20 > $ cat scr.sql > \set vl_id 19 > \set ECHO none > \pset tuples_only on > \pset pager off >=20 > select script_drop from proceso_actualiza_fdw where id =3D :vl_id; >=20 > select script_import from proceso_actualiza_fdw where id =3D :vl_id; >=20 > \q >=20 > 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 MODIFICADAS =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+ >=20 > How can I eliminate "Pager usage is off." and the "+"=C2=A0 at the end of= each row? Rather than disabling the pager with a \pset command, set the PAGER environ= ment variable to an empty string before calling "psql". To get rid of the "+" at the end of the line, use unaligned output. I use the options -A, -t and -q when calling "psql" from a shell script. So your shell script could look like PAGER=3D'' psql -Atq -U ... -d ... -f ... > 2. If in the psql script I want to pass variable values from an anonymous= block to the rest of the script,=C2=A0how can=C2=A0I proceed?. For example >=20 > DO $$ > DECLARE > =C2=A0 vl_id integer; > BEGIN > =C2=A0-- vl_id is set inside the procedure > =C2=A0 call my_procedure(vl_id); > END $$; >=20 > select script_drop from proceso_actualiza_fdw where id =3D :vl_id; >=20 > select script_import from proceso_actualiza_fdw where id =3D :vl_id; >=20 > The script output file is the result set=C2=A0from the queries. >=20 > I've tried=C2=A0with \set myvar but this doesn't works You cannot grab any output from a DO statement. I recommend that you don't= use it. Try something like the following in your "psql" script: -- without a DO statement CALL my_procedure(NULL) \gset That will define a variable that has the same name as the parameter of the = procedure and set its value to the return value of the procedure. Yours, Laurenz Albe