pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
To: Ron Johnson <ronljohnsonjr@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: psql: print values and return the COUNT(*) value to bash?
Date: Mon, 29 Dec 2025 09:12:36 +0100
Message-ID: <20251229091236.4ebacf38@karst> (raw)
In-Reply-To: <CANzqJaBX-SZZcHn71xgqtSKx6ekZGdHPSgCmP2co5=-KDu4Q-Q@mail.gmail.com>
References: <CANzqJaBX-SZZcHn71xgqtSKx6ekZGdHPSgCmP2co5=-KDu4Q-Q@mail.gmail.com>

On Mon, 29 Dec 2025 02:21:41 -0500
Ron Johnson <ronljohnsonjr@gmail.com> wrote:
…
> 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.

You should probably output your result from psql in a parsable way (CSV ? TSV ?
custom ?) for your bash script, then print values from bash. The commands
"column" or "printf" could help you format a pretty table if really needed.

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

Not in a clean way. To make psql return something else than 0, you need to
trigger an error with a failing query to make it return 3 when ON_ERROR_STOP is
enabled.





view thread (5+ messages)  latest in thread

Message-ID: <20251229091236.4ebacf38@karst>
Permalink:  ../20251229091236.4ebacf38@karst/
Also on:    postgresql.org/message-id/20251229091236.4ebacf38@karst

 · 

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: pgsql-general@postgresql.org
  Cc: jgdr@dalibo.com, ronljohnsonjr@gmail.com
  Subject: Re: psql: print values and return the COUNT(*) value to bash?
  In-Reply-To: <20251229091236.4ebacf38@karst>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox