Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1va8Ms-0047JC-1D for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2025 08:12:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1va8Mr-00Fump-1D for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2025 08:12:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1va8Mq-00FumZ-39 for pgsql-general@lists.postgresql.org; Mon, 29 Dec 2025 08:12:41 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1va8Mp-003MlS-0P for pgsql-general@postgresql.org; Mon, 29 Dec 2025 08:12:41 +0000 Received: from karst (82-65-23-130.subs.proxad.net [82.65.23.130]) by mail.dalibo.com (Postfix) with ESMTPSA id 4208F26829; Mon, 29 Dec 2025 09:12:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dalibo.com; s=a; t=1766995957; bh=IIwhvvNXwsIpqDMAVYaeRjnyTYsOQLdh1O6jTv9Xrts=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KOczRWk2HF4QPvMZQbpJiP4Ttxxdy9+acSdBfbvd0mCXD5x1ixZ15b6+eCxE31cDj zUK0dzJwQrV+53GFPQhp9EGB1ncKLRO8vIGT/AMm6N9LV48myTajTgsLhaAV7hWtz7 t/h+Bb4tEbYgLllbmpMM8ouSjGFNPc6afFu8io0E= Date: Mon, 29 Dec 2025 09:12:36 +0100 From: Jehan-Guillaume de Rorthais To: Ron Johnson Cc: pgsql-general Subject: Re: psql: print values and return the COUNT(*) value to bash? Message-ID: <20251229091236.4ebacf38@karst> In-Reply-To: References: Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 29 Dec 2025 02:21:41 -0500 Ron Johnson wrote: =E2=80=A6 > 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 = =3D=3D > 0. You should probably output your result from psql in a parsable way (CSV ? T= SV ? 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_STO= P is enabled.