Re: SQL from shell script - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: SQL from shell script
Date
Msg-id 20050114195703.GA19160@winnie.fuhr.org
Whole thread Raw
In response to Re: SQL from shell script  (Geoffrey <esoteric@3times25.net>)
List 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/

pgsql-novice by date:

Previous
From: Geoffrey
Date:
Subject: Re: SQL from shell script
Next
From: Sean Davis
Date:
Subject: Re: SQL from shell script