This is a variation of the same:

a=`psql -U postgres -h my.host.dom -Atc "select col1 from sometable where 
col2=6"  dbname`
echo $a

Note that the -U and -h can specify the user name and hostname if necessary.
-A gets the data unaligned
-t gets the data without the decorations
-c "query" specifies the query to run
dbname is required if it is not the default.

Also see psql --help 

elein

On Thu, Jun 29, 2006 at 11:40:49AM -0500, Scott Marlowe wrote:
> On Thu, 2006-06-29 at 11:29, Jasbinder Bali wrote:
> > isn't my normal bash script different from psql.
> > In a bash script how wud u specify the db parameters
> 
> Look at how I'm doing it here:
> 
> >         > > query="select * from sometable"; 
> >         > > a=`echo $query|psql -tq dbname`;
> 
> Note that I'm calling psql from within a bash script. So, the connection
> params are the same as for psql, cause that's what I'm using.
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq
> 

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to