psql 警告:在使用连接 URI 时,忽略额外的命令行参数 x。

huangapple go评论50阅读模式
英文:

psql warning: extra command-line argument x ignored when using Connection URIs

问题

我正在尝试使用psql命令和连接URI执行SELECT查询

但我收到以下错误:

我确实连接到了数据库,但忽略了查询

另一方面,我可以使用URI创建数据库

我尝试过使用引用

PostgreSQL 14.4,由Visual C++版本1914编译,64位。

英文:

I am trying to execute a SELECT using psql command and Connection URIs
psql postgresql://postgres:admin@localhost:5432/newDB -c "select current_date;"

But I get this error :
psql: warning: extra command-line argument "select current_date;" ignored
I do connect to the night database but ignore the query

On the other hand, I am able to create a database using URIs
createdb --maintenance-db postgresql://postgres:admin@localhost:5432 'newDB'

I have tried the solutions described here: https://tapoueh.org/blog/2019/09/postgres-connection-strings-and-psql/
psql -Atx postgresql://taop@localhost:5432/taop -c 'select current_date'

But I got the same message.

I tried using quotes for the uri but I got the same message

PostgreSQL 14.4, compiled by Visual C++ build 1914, 64-bit

答案1

得分: 1

你似乎正在使用Windows。 在Windows上,所有开关参数(如-c something)必须位于所有非开关参数(如裸连接字符串)之前,因为Windows参数解析库在找到非开关参数后停止处理开关。

因此,要么交换参数的顺序,使连接字符串最后出现,要么将连接字符串转换为开关格式,将-d放在其前面。

英文:

You seem to be using Windows. On Windows, all switch arguments (like -c something) must precede all non-switch arguments (like the naked connection string), as the Windows argument-parsing library stops processing switches once it finds a non-switch.

So either swap the ordering of your arguments so the connection string comes last, or convert the connection string to a switch format by putting -d in front of it.

答案2

得分: 0

似乎psql命令正在解释-c选项和SQL查询作为独立的参数,导致查询被忽略。一种可能的解决方案是将整个命令(包括URI和查询)用引号括起来,像这样:

psql "postgresql://postgres:admin@localhost:5432/newDB" -c "select current_date;"

或者,您可以尝试使用-X选项来强制psql忽略URI之后的任何后续命令行参数,像这样:

psql -X "postgresql://postgres:admin@localhost:5432/newDB" -c "select current_date;"
英文:

It seems that the psql command is interpreting the -c option and the SQL query as separate arguments, causing the query to be ignored. One possible solution is to enclose the entire command (including the URI and query) in quotes, like this:

psql "postgresql://postgres:admin@localhost:5432/newDB" -c "select current_date;"

Alternatively, you could try using the -X option to force psql to ignore any subsequent command-line arguments after the URI, like this:

psql -X "postgresql://postgres:admin@localhost:5432/newDB" -c "select current_date;"

huangapple
  • 本文由 发表于 2023年2月23日 21:39:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定