Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql: run SQL commands using psql in commandline

Tags:

postgresql

I have the below three lines to be run in commandline using psql how can i do it.

CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;

I just want to pass the sql strings as it is.

like image 255
Santhosh Avatar asked Jan 01 '26 07:01

Santhosh


1 Answers

As per the docs psql -c 'command;'

psql -c 'CREATE DATABASE myproject;' -c "CREATE USER myprojectuser WITH PASSWORD 'password';" -c 'GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;'
like image 75
Scoots Avatar answered Jan 03 '26 23:01

Scoots



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!