Re: Compare the resulta of a count sql into bash

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: manuel antonio ochoa <manuel8aalfaro(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Compare the resulta of a count sql into bash
Date: 2011-01-27 04:49:53
Message-ID: AANLkTims5qiOYq5m9fekrtjPdtpeJYVgeniXKO0Bm-eq@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jan 26, 2011 at 12:07 PM, manuel antonio ochoa
<manuel8aalfaro(at)gmail(dot)com> wrote:
>
> Hello,
> I have the next :
>
> COUNTONE=`/var/lib/pgsql/bin/./psql -U 'Thor'   -d princlocal -p 5432 -h
> 192.170.1.82  -c "select count(*) from monterrey.${NOMBRETB}"`
> COUNTTWO=`/var/lib/pgsql/bin/./psql -U 'Thor'   -dprinclocal -p 5432 -h
> 192.170.1.82  -c "select count(*) from monterrey.$nombre where recibo
> between '$FI' and '$FF'"
>
> I want to compare the result countone with countwo  how does it works  ?

It looks to me like COUNTONE and COUNTWO are going to get the strings
returned by psql, i.e. something not terribly helpful like: "count
------- 64 (1 row)". If you were expecting COUNTONE and COUNTWO to
hold exit codes, use the $? variable instead. But the exit code of
psql isn't what you want, either -- psql simply exits with something
like 0 or 1 depending on whether the command(s) succeeded.

Of course, you could cook up some script to parse the text returned by
psql to figure out the rowcounts, but that's a much greater pain than
just implementing whatever you're trying to do in a scripting language
using a PostgreSQL database adapter.

Josh

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Marlowe 2011-01-27 06:11:17 Re: Compare the resulta of a count sql into bash
Previous Message Craig Ringer 2011-01-27 00:11:08 Re: check files .backup