From: | Abel Camarillo <acamari(at)the00z(dot)org> |
---|---|
To: | Alex Gadea <alex(dot)gadea(at)apptik(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to get variable out to shell script |
Date: | 2009-09-20 23:49:56 |
Message-ID: | 20090920234956.GA16823@maetel.00z |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, Sep 20, 2009 at 04:49:03PM -0500, Alex Gadea wrote:
> I am using psql to call an external sql file that executes a simple select count(*):
>
> ie: select into ct count(*) from table;
>
> I can't figure out how to make the ct variable available to the shell script once the external sql file completes execution. What I am trying to do is run the count command against a table in two different databases on two different servers and then compare the variables.
>
> Any ideas?
>
> Thanks in advance.
>
> Alex
>
>
I tend to use a lot of shell scripts in my production code, i would do
something like this:
#!/bin/sh
dbname=
user=
password=
tables="t1 t2"
for i in $tables;
do
psql -c "\copy (select count(*) from $i) to pstdout csv" \
"dbname=$dbname user=$user password=$password"
done
#END#######################
that would print two lines...
1234134
4565
that are the count(*) of each table.
Use your imagination.
Saludos.
--
DISCLAIMER: http://goldmark.org/jeff/stupid-disclaimers/
This message will self-destruct in 3 seconds.
From | Date | Subject | |
---|---|---|---|
Next Message | Jerry LeVan | 2009-09-21 01:41:45 | Re: How can I make a two arch libpq for snow leopard? |
Previous Message | Scott Ribe | 2009-09-20 23:47:39 | Re: How can I make a two arch libpq for snow leopard? |