How to pipe SQL to psql

If you want to pass a sql string to psql from the command line without having to run psql and entering from within you can pipe it.

For example you want the contents of a table called reciprocal. Here is how:

echo "select * from reciprocal" | psql database

Links