【发布时间】:2021-12-30 16:46:58
【问题描述】:
我正在尝试使用 psql 运行以下命令,但 --file 参数被忽略事件,我设法连接到数据库。
psql "postgresql://postgres:admin12345@localhost:5432/Phoenix" -f "tables/book.sql"
终端上的输出如截图所示。
我在这里缺少什么?提前致谢。
【问题讨论】:
标签: windows postgresql psql
我正在尝试使用 psql 运行以下命令,但 --file 参数被忽略事件,我设法连接到数据库。
psql "postgresql://postgres:admin12345@localhost:5432/Phoenix" -f "tables/book.sql"
终端上的输出如截图所示。
我在这里缺少什么?提前致谢。
【问题讨论】:
标签: windows postgresql psql
在谷歌搜索并浪费时间测试不同的 SO 答案之后,这对我有用:
psql -f "tables/book.sql" "postgresql://postgres:admin12345@localhost:5432/Phoenix"
看起来 psql 命令要求命令行参数出现在连接字符串之前。这有点奇怪,但它对我有用。
引号也是可选的。这也有效:
psql -f tables/book.sql postgresql://postgres:admin12345@localhost:5432/Phoenix
我尝试更改代码页,如 psql 文档 psql docmentation 中的“Windows 用户注释”部分所示。结果是警告不再显示,但如果连接字符串在它们之前,命令行参数仍然会被忽略,如下面的日志所示:
C:\Users\Zack
λ cmd.exe /c chcp 1252
Active code page: 1252
C:\Users\Zack
λ psql postgresql://postgres:admin12345@localhost:5432/Phoenix -f "tables/book.sql"
psql: warning: extra command-line argument "tables/book.sql" ignored
psql (13.2)
Type "help" for help.
Phoenix=#
Theo 现在唯一对我有用的解决方法是将其他 args 置于连接字符串之前。
如果有人知道为什么命令行参数应该在连接字符串之前,请提供更多详细信息。
【讨论】:
psql "postgresql://postgres:@localhost:5432/test" -f "test_sql.sql" 和 psql -d test -U postgres -f "test_sql.sql" 在 Linux 上对我来说工作得很好。