I have trouble to execute a SQL script via command line, this is what I have
"C:\..\psql.exe" -h my_server_host -U username -c 'CREATE DATABASE test;'
I got this error:
psql: warning: extra command-line argument "test;'" ignored
psql: FATAL: database "DATABASE" does not exist
I am on Windows 7 with Postgresql 9.3.
Any idea how to do that?
You must connect to a database to run a command, even if you want to run CREATE DATABASE
, so:
"C:\..\psql.exe" -h my_server_host -U usr -c 'CREATE DATABASE test;' postgres
(As @Craig cleared up, it must be double quotes for Windows.)
Using the default maintenance db postgres
here.
There is a better option for the purpose at hand, though: createdb from the command-line directly.
Windows's cmd.exe
expects double quotes on arguments, not single quotes.
"CREATE DATABASE test;"
http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With