Re: psql: print values and return the COUNT(*) value to bash?
В списке pgsql-general по дате отправления:
| От | hubert depesz lubaczewski |
|---|---|
| Тема | Re: psql: print values and return the COUNT(*) value to bash? |
| Дата | |
| Msg-id | aVNinWjzpU3l6yHB@depesz.com обсуждение |
| Ответ на | Re: psql: print values and return the COUNT(*) value to bash? (Vincent Veyron <vv.lists@wanadoo.fr>) |
| Список | pgsql-general |
On Mon, Dec 29, 2025 at 05:40:23PM +0100, Vincent Veyron wrote:
> > =$ bash z.sh
> > Rowcount = 1
> > Full output:
> > days_ago | oldest_date | cnt
> > ------------------------+-------------------------------+-----
> > 7 days 03:48:07.348247 | 2025-12-22 07:22:32.593814+01 | 212
> > (1 row)
> >
>
> IIUC, Ron wants the 212 number?
>
> Maybe use the -t switch, and 'cut' :
Ah, that part I misunderstood.
Well, if there is only 1 row returned, always, then the simplest thing
would be to change
> row_count="$( tail -n1 <<< "${returned}" | cut -d "|" -f 3)"
to this:
row_count="$( awk 'NR==3 {print $NF}' <<< "${returned}" )"
format can stay the same, we don't need to psql -t, or -a, and it will
just work :)
Best regards,
depesz
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера