I need to execute postgresql queries from command line using psql -c command. For every psql command, it opens a new tcp connection to connect to the database server and exe
The --file parameter executes a file's content
--file
psql -U postgres -h -f "my_file.psql"
All the output will be sent to standard output
http://www.postgresql.org/docs/current/static/app-psql.html