I'm using this command within a powershell script to extract a single value into a file
我在PowerShell脚本中使用此命令将单个值提取到文件中
.\psql -U myowner -d myDB -c "SELECT last_value FROM pg_sequences WHERE sequencename ='mytest'" -o c:\test.dat
This works OK, and dumps the output to test.dat as follows
这可以正常工作,并将输出转储到test.dat,如下所示
last_value
-------------
13446137112
(1 row)
How do I loose the column header and the footer? I just want the value alone, no bumpf. i.e. just a file containing
如何松开列页眉和页脚?我只想要价值,不要颠簸。即仅包含以下内容的文件
13446137112
I could probably hack something with powershell, but was hoping for a more elegant formatting option within psql
我也许可以用PowerShell破解一些东西,但我希望在psql中有一个更优雅的格式选项。
(psql v13.1, powershell v5.1, windows 11)
(PSQL v13.1、PowerShell v5.1、Windows 11)
UPDATE - Abdul Azizs' answer is correct (thank-you). '-t' strips out the header and footer. Bonus points for striping off the leading spaces and extra blank lines
更新-阿卜杜勒·阿齐兹的答案是正确的(谢谢)。‘-t’去掉页眉和页脚。去掉前导空格和多余空行的加分
更多回答
优秀答案推荐
You can add in the -t
/ --tuples-only
flag to enable tuples-only, this suppresses the column names and footers.
您可以添加-t/--tuples-only标志来启用仅元组,这将取消列名和页脚。
.\psql -U myowner -d myDB -t -c "SELECT last_value FROM pg_sequences WHERE sequencename ='mytest'" -o c:\test.dat
With the -t
option, psql will output only the tuple data without the column header and footer.
使用-t选项时,psql将只输出没有列页眉和页脚的元组数据。
Check out PostgreSQL's app-psql for more info.
有关更多信息,请查看PostgreSQL的app-psql。
更多回答
我是一名优秀的程序员,十分优秀!