Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

postgres run query from command line

## Using SQL file
PGPASSWORD=myPassword psql -h myDbHost -U myUser -p 5432 -d my_db -a -q -f /path/to/sql/file.sql
## Or
PGPASSWORD=myPassword psql -h myDbHost -U myUser -p 5432 -d my_db < /path/to/sql/file.sql

## Using command
PGPASSWORD=myPassword psql -h myDbHost -U myUser -p 5432 -d my_db -c "select * from my table limit 1;"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #postgres #run #query #command #line
ADD COMMENT
Topic
Name
2+3 =