Re: SQL from shell script

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Geoffrey <esoteric(at)3times25(dot)net>
Cc: pgsqlnovice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL from shell script
Date: 2005-01-14 19:57:03
Message-ID: 20050114195703.GA19160@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Jan 14, 2005 at 02:32:48PM -0500, Geoffrey wrote:

> echo "select * from table1;
> select * from table2;
> select * from table3;
> "|psql rnd

You could also use a here-document if your shell supports it (most do):

psql rnd <<END_OF_SQL
select * from table1;
select * from table2;
select * from table3;
END_OF_SQL

> Still, you'll have to deal with the password a different way likely.

You could use the PGPASSWORD environment variable, although doing
so is deprecated due to the security risk (many operating systems
make environment variables visible to other processes). Another
possibility would be to use ~/.pgpass; see "The Password File"
in the libpq chapter of the documentation. Or, if the security
model allows it, tweak pg_hba.conf so it doesn't require password
authentication (some security can be maintaned by using ident
authentication if the system supports it).

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Sean Davis 2005-01-14 20:05:08 Re: SQL from shell script
Previous Message Geoffrey 2005-01-14 19:32:48 Re: SQL from shell script