Postgresql – access columns returned by psql from bash

postgresqlpsql

I want to use value returned by psql in bash. This is the script:

psql "connection parameters" -c "SELECT pg_database_size('dbname');"

The output is like this:

 pg_database_size 
------------------
          5773072
(1 row)

But I only want the 5773072 so I can use it in logging. Can anyone help?

Best Answer

The -t (--tuples-only) option might be used also:

psql "connection parameters" -t -c "SELECT pg_database_size('dbname');"