I'm writing a psql sql script to generate an sql script. The way I do this, is by writing every ouputline to a temptable and later on \copy that to the output sql file.
I'd like to include the \conninfo output to the header of the file but I can't seem to capture its output into a variable.
What I tried :
\set conninfo \conninfo
\o tempfile.txt
\conninfo
\o
\set conninfo `cat tempfile.txt`
None seem to work, I assume \conninfo writes to STDERR.
Does anybody have a solution ?
I'm writing a psql sql script to generate an sql script. The way I do this, is by writing every ouputline to a temptable and later on \copy that to the output sql file.
I'd like to include the \conninfo output to the header of the file but I can't seem to capture its output into a variable.
What I tried :
\set conninfo \conninfo
\o tempfile.txt
\conninfo
\o
\set conninfo `cat tempfile.txt`
None seem to work, I assume \conninfo writes to STDERR.
Does anybody have a solution ?
Share Improve this question asked Feb 7 at 19:50 Peter Van BiesenPeter Van Biesen 111 silver badge2 bronze badges New contributor Peter Van Biesen is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 1From here:
https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-VARIABLES
\set con_info 'Connected to ' :DBNAME ' at ' :PORT ' as ' :USER
\echo :con_info
Connected to test at 5432 as postgres
This uses the built in variables provided in psql
to build a connection description.