gpt4 book ai didi

Using psql command line within powershell - and formatting the output(在PowerShell中使用psql命令行-并格式化输出)

转载 作者:bug小助手 更新时间:2023-10-25 12:31:19 25 4
gpt4 key购买 nike



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。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com