3

I am trying to make a one line psql request. I would like to send both credentials and query in the same time. I am using this :

psql.exe "dbname=dbname user=postgres password=postgres host=localhost" -c 'select * from table'

Actually if i take back the -c option it works but right now it sends me this :

psql: attention : option supplémentaire « 'select » ignorée
psql: attention : option supplémentaire « * » ignorée
psql: attention : option supplémentaire « from » ignorée
psql: attention : option supplémentaire « view' » ignorée

The connection to the database worked but thoose logs are in french but they mean "care : option skipped".

I tried with Url request

psql.exe postgresql://postgres:postgres@localhost/dbname -c 'select * from view'

But this is the same.

Do you have any idea where i am misplaying this ?

Thanks !

1
  • I am using the latest version of PostgreSQL : 13 ! Commented Oct 22, 2020 at 7:20

3 Answers 3

4

Ok guys, found the solution. After a better read of the --help, i figured that

psql [OPTIONS]... [NOM_BASE [NOM_UTILISATEUR]]

Connexion options are to be used after the query so instead of psql [CONNEXION] -c "blabla" Use this

psql -c "select * from table" "dbname=dbname user=user password=password host=host"

or

psql -c "select * from table" postgresql://user:password@host/dbname

Take care about your double quotes too.

Bye,

Sign up to request clarification or add additional context in comments.

Comments

2
psql postgresql://myusername:[email protected]:5432/myDB

Comments

0

You have to use double quotes, not single quotes, to protect a string with spaces in Windows' cmd.exe.

1 Comment

Agreed. Fact is, with the double quote, it just gonna skip the whole in once!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.