Bash - pg_query.sh

#!/bin/bash

# Run query command as user postgres and append current date
su -c "psql -U postgres -d x -c \"select x from x where x = 'x';\"" postgres >>output.dmp && date >>output.dmp