On Sun, Sep 20, 2009 at 04:49:03PM -0500, Alex Gadea wrote:
> 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.
Just tell psql not to output any surrounding stuff and then just
redirect as normal:
ct="`psql -tc 'select count(*) from table;'`"
echo $ct
I expect it'll probably be easier to use a "real" scripting language
though; Python and Perl both have reasonable libraries for talking to
Postgres with. Python would be something like:
import psycopg2;
conn = psycopg2.connect("dbname='db1'");
cur = conn.cursor();
cur.execute ("select count(*) from table;");
[[n]] = cur.fetchall();
It's a bit of a fiddle to change over, but having a something more
expressive than a bourne shell can help.
--
Sam http://samason.me.uk/