displayName
displayName

Reputation: 215

"psql: warning: extra command-line argument" when attempting to run sql files from Windows cmd line

I'm attempting to run this statement in the cmd prompt so that I can execute an sql script over a database.

"C:\Users\Name\Desktop\psql.exe" -U someUsername -h localhost someDbName -f "C:\Users\Name\Desktop\script.sql"

However, I'm getting back the error messages:

psql: warning: extra command-line argument "-f" ignored

psql: warning: extra command-line argument "C:\Users\Name\Desktop\script.sql" ignored

New to all of this, so any help would be appreciated!

Upvotes: 1

Views: 7439

Answers (3)

Scott ATX
Scott ATX

Reputation: 31

Edi's method was what I used successfully, here is the same thing but with extra parameters.. I'm running this on a windows 10 client with psql shell installed, from a batch file against a greenplum database (postgres DW)

test.bat contents, p is port:

set PGPASSWORD=yourPW
"C:\Program Files\PostgreSQL\13\bin\psql.exe" -h instancename.blah.com -U scott -p 6420 -f "c:\temp\postgresversion.sql" -d dbnamehere

posgresversion.sql contents:

SELECT Version();

Upvotes: 0

Edi
Edi

Reputation: 2301

This was my workaround!

@ECHO OFF
set PGPASSWORD=postgres
psql -U postgres -f "C:\Users\projects\Project\drop_create_db.sql" -d postgres

Upvotes: 2

user330315
user330315

Reputation:

If you enter psql --help you will see the following summary:

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

which means the database name must come after all "options", or it must be passed as an option (using -d)

So either:

psql.exe -U someUsername -h localhost -d someDbName -f "C:\Users\Name\Desktop\script.sql"

or

psql.exe -U someUsername -h localhost -f "C:\Users\Name\Desktop\script.sql" someDbName 

Upvotes: 4

Related Questions