Thread: PSQL: "\set ECHO all" doesn't work with "\o"

PSQL: "\set ECHO all" doesn't work with "\o"

From
Alberto Benini
Date:

Hi all,

I haven’t understand how to redirect SQL errors on output file.

 

Our goal is to have a psql script with:

 

\set ON_ERROR_STOP true

\set ECHO all

\o log/update.log;

\i update.sql;

 

 

..but in the log file we don’t see any sql error

 

KR,

Alberto

 

Re: PSQL: "\set ECHO all" doesn't work with "\o"

From
"David G. Johnston"
Date:
On Wed, Feb 23, 2022 at 11:18 AM Alberto Benini <alberto.benini@tasgroup.eu> wrote:

Hi all,

I haven’t understand how to redirect SQL errors on output file.

 

Our goal is to have a psql script with:

 

\set ON_ERROR_STOP true

\set ECHO all

\o log/update.log;

\i update.sql;

 

 

..but in the log file we don’t see any sql error



You need to do this in your shell, IIRC:

psql [...] --file update.sql > log/update.log 2>&1

That trying to do the same with the \o meta-command fails should not be surprising - the documentation explicitly says:
“Query results” includes all tables [...] but not error messages."

David J.