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 1vaSG3-008gH6-1P for pgsql-general@arkaria.postgresql.org; Tue, 30 Dec 2025 05:27:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vaSG2-002b43-1I for pgsql-general@arkaria.postgresql.org; Tue, 30 Dec 2025 05:26:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vaSG1-002b3s-39 for pgsql-general@lists.postgresql.org; Tue, 30 Dec 2025 05:26:58 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vaSG0-003I1Q-38 for pgsql-general@postgresql.org; Tue, 30 Dec 2025 05:26:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description; bh=CvkgdEjLN28igeiav2FINAPNei8qwnb1Sxi+8wTPJPs=; b=LpTNMQ+2vCsmF3GNkS/9NDkIjC wvBUcy6I7w3PZEJbYetXOO9LT4jkbQnUCOTMpz8PE8J7ruAqbkQ7MsGeT77OandzzQMVjG47DCXUi RHfHSYev8EPo6p9w8OeOYTjjdO0z1F9B8xET9BCDHLXWpqsKhangabHPoxVY2MASKgfY=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1vaSFx-00HZPd-0p; Tue, 30 Dec 2025 06:26:53 +0100 Date: Tue, 30 Dec 2025 06:26:53 +0100 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Vincent Veyron Cc: Ron Johnson , pgsql-general Subject: Re: psql: print values and return the COUNT(*) value to bash? Message-ID: Reply-To: depesz@depesz.com References: <20251229174023.106f1c1f2212c7372615673c@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20251229174023.106f1c1f2212c7372615673c@wanadoo.fr> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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