public inbox for [email protected]
help / color / mirror / Atom feedFrom: hubert depesz lubaczewski <[email protected]>
To: Vincent Veyron <[email protected]>
Cc: Ron Johnson <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: psql: print values and return the COUNT(*) value to bash?
Date: Tue, 30 Dec 2025 06:26:53 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <CANzqJaBX-SZZcHn71xgqtSKx6ekZGdHPSgCmP2co5=-KDu4Q-Q@mail.gmail.com>
<[email protected]>
<[email protected]>
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
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: psql: print values and return the COUNT(*) value to bash?
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox