psql: print values and return the COUNT(*) value to bash? - Mailing list pgsql-general

From Ron Johnson
Subject psql: print values and return the COUNT(*) value to bash?
Date
Msg-id CANzqJaBX-SZZcHn71xgqtSKx6ekZGdHPSgCmP2co5=-KDu4Q-Q@mail.gmail.com
Whole thread Raw
Responses Re: psql: print values and return the COUNT(*) value to bash?
Re: psql: print values and return the COUNT(*) value to bash?
List pgsql-general
Currently I do this in a bash script:
Tbl=table_1
Fld=field_1
Sql="SELECT CURRENT_TIMESTAMP - MIN($Fld) AS days_ago
          , MIN($Fld) as oldest_date
          , COUNT(*) AS cnt 
     FROM $Tbl;"
psql -h <host> <db> -Xc "${Sql}"
 days_ago | oldest_date | cnt
----------+-------------+-----
          |             |   0
(1 row)

More stuff happens after this.  I want to print out these four lines, but also test the COUNT(*) value and bypass other bash commands if the count == 0.

Is there any relatively simple way to do this (psql print and return count(*))?

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Combining metavariables and table names
Next
From: Jehan-Guillaume de Rorthais
Date:
Subject: Re: psql: print values and return the COUNT(*) value to bash?