gpt4 book ai didi

bash - 在 "\copy"psql 命令行中使用 sql 文件

转载 作者:行者123 更新时间:2023-11-29 09:51:15 25 4
gpt4 key购买 nike

我正在尝试从 bash 文件编写查询脚本,但选择查询在文件中。为了兼容性和测试,我想保持这种方式。

简而言之,我想写这样的东西:

psql -c data_base "\copy (<file.sql>) To './test.csv' With CSV"

你知道怎么做吗?

编辑

“file.sql”包含一个查询:

$cat file.sql
$SELECT country FROM world;

最佳答案

您可以使用 bash替换为,

psql -c data_base "\copy ($(<file.sql)) To './test.csv' With CSV"

$(<file)展开 file 的内容

关于bash - 在 "\copy"psql 命令行中使用 sql 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42065299/

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