admin管理员组文章数量:1221386
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.
本文标签: How do I capture the output of conninfo into a variable in postgresql39s psqlStack Overflow
版权声明:本文标题:How do I capture the output of conninfo into a variable in postgresql's psql? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739294143a2156829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论