pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCompare the resulta of a count sql into bash
4+ messages / 4 participants
[nested] [flat]
* Compare the resulta of a count sql into bash
@ 2011-01-26 17:07 manuel antonio ochoa <manuel8aalfaro@gmail.com>
0 siblings, 3 replies; 4+ messages in thread
From: manuel antonio ochoa @ 2011-01-26 17:07 UTC (permalink / raw)
To: pgsql-sql
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 ?
thnks
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Compare the resulta of a count sql into bash
@ 2011-01-27 04:49 Josh Kupershmidt <schmiddy@gmail.com>
parent: manuel antonio ochoa <manuel8aalfaro@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Josh Kupershmidt @ 2011-01-27 04:49 UTC (permalink / raw)
To: manuel antonio ochoa <manuel8aalfaro@gmail.com>; +Cc: pgsql-sql
On Wed, Jan 26, 2011 at 12:07 PM, manuel antonio ochoa
<manuel8aalfaro@gmail.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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Compare the resulta of a count sql into bash
@ 2011-01-27 06:11 Scott Marlowe <scott.marlowe@gmail.com>
parent: manuel antonio ochoa <manuel8aalfaro@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Scott Marlowe @ 2011-01-27 06:11 UTC (permalink / raw)
To: manuel antonio ochoa <manuel8aalfaro@gmail.com>; +Cc: pgsql-sql
On Wed, Jan 26, 2011 at 10:07 AM, manuel antonio ochoa
<manuel8aalfaro@gmail.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 ?
echo $((COUNTONE-COUNTTWO));
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Compare the resulta of a count sql into bash
@ 2011-01-27 10:20 Jasen Betts <jasen@xnet.co.nz>
parent: manuel antonio ochoa <manuel8aalfaro@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Jasen Betts @ 2011-01-27 10:20 UTC (permalink / raw)
To: pgsql-sql
On 2011-01-26, manuel antonio ochoa <manuel8aalfaro@gmail.com> wrote:
> --0015174be152ceb275049ac2dc95
> Content-Type: text/plain; charset=ISO-8859-1
>
> 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 ?
you need -t
COUNTONE=`/var/lib/pgsql/bin/./psql -t -U 'Thor' -d princlocal -p 5432 -h 192.170.1.82 -c "select count(*) from monterrey.${NOMBRETB}"`
COUNTTWO=`/var/lib/pgsql/bin/./psql -t -U 'Thor' -d princlocal -p 5432 -h 192.170.1.82 -c "select count(*) from monterrey.$nombre where recibo between '$FI' and '$FF'"`
or like this:
CONN="user=Thor database=princlocal port=5432 host=192.170.1.82"
PSQL=/var/lib/pgsql/bin/psql
COUNTONE=`$PSQL "$CONN" -t -c "select count(*) from monterrey.${NOMBRETB}"`
COUNTTWO=`$PSQL "$CONN" -t -c "select count(*) from monterrey.$nombre where recibo between '$FI' and '$FF'"`
--
⚂⚃ 100% natural
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2011-01-27 10:20 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-01-26 17:07 Compare the resulta of a count sql into bash manuel antonio ochoa <manuel8aalfaro@gmail.com>
2011-01-27 04:49 ` Josh Kupershmidt <schmiddy@gmail.com>
2011-01-27 06:11 ` Scott Marlowe <scott.marlowe@gmail.com>
2011-01-27 10:20 ` Jasen Betts <jasen@xnet.co.nz>
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