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
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.