I'm not very good with PSQL. But it should work in the same manor MySQL does.
My normal way of running SQL questions against a MySQL from bash is to either create a .sql file with the query or use HERE DOC.
Using HERE DOC
Code:
# psql <<EOF
SELECT
*
FROM
tblname;
EOF
You can put this all on one row also, the formating isn't vital, what is vital is the EOF on it's own row.
This can work too, it's the same basically
Code:
# psql <<< "SELECT * FROM tblname;"
Using SQL file
Code:
# psql < inputfile.sql
using this in a script can look something like this:
Code:
#!/bin/bash
/path/to/psql <<EOF
select this, that, the_other from orders
where x y and z
group by this
order by that ;
EOF
/path/to/psql <<EOF
select this, that, the_other from customer_bills
where x y and z
group by this
order by that ;
EOF
/path/to/psql <<EOF
select this, that, the_other from customer_bills, orders
where x y and z
group by this
order by that ;
EOF
Best regards
Fredrik Eriksson