Postgresql – Batch for PostgreSQL query

command lineplsqlpostgresqlpostgresql-9.4

1) The pgpass.conf (of PostgreSQL) is:

localhost:5432:*:postgres:mypassword

I have no experience with batch and I have spent the day searching in the net.
I'm using Windows – if that matters.

2) I tried with a file.bat as:

cd C:
start "" "C:\Program Files\PostgreSQL\9.4\bin\psql.exe" "C:\Users\utente\Desktop\1Giswater impNode.sql"
pause
start "" "C:\Program Files\PostgreSQL\9.4\bin\psql.exe" "C:\Users\utente\Desktop\2Giswater impArc.sql"
pause
start "" "C:\Program Files\PostgreSQL\9.4\bin\psql.exe" "C:\Users\utente\Desktop\3assegnazione enet.sql"
pause

After typing my password the result is:

psql: fe_sendauth: no password supplied

3) I've written a simple file.bat, which is:

cd C:\Program Files\PostgreSQL\9.4\bin\
pause
rem psql --help
pause
psql   -e -a -f="C:\Users\utente\Desktop\1Giswater impNode.sql"   -d=postgres  -U=postgres

The result is:

psql: opzione di connessione errata

What am I missing?

Best Answer

You are passing the username incorrectly:

The "short" parameter names don't use the = sign:

So it should either be:

psql -e -a -f"C:\Users\utente\Desktop\1Giswater impNode.sql" -dpostgres  -Upostgres

or, when using the long parameter names:

psql -e -a --file="C:\Users\utente\Desktop\1Giswater impNode.sql" --dbname=postgres  --username=postgres