psql: print values and return the COUNT(*) value to bash?

Поиск
Список
Период
Сортировка
От Ron Johnson
Тема psql: print values and return the COUNT(*) value to bash?
Дата
Msg-id CANzqJaBX-SZZcHn71xgqtSKx6ekZGdHPSgCmP2co5=-KDu4Q-Q@mail.gmail.com
обсуждение исходный текст
Ответы Re: psql: print values and return the COUNT(*) value to bash?
Re: psql: print values and return the COUNT(*) value to bash?
Список 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 по дате отправления: