Re: How to query pgsql from a BASH script ? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: How to query pgsql from a BASH script ?
Date
Msg-id 20050404145605.GA9422@svana.org
Whole thread Raw
In response to Re: How to query pgsql from a BASH script ?  (Pavel Stehule <stehule@kix.fsv.cvut.cz>)
List pgsql-general
On Sun, Apr 03, 2005 at 11:17:41PM +0200, Pavel Stehule wrote:
> test=# select * from foo;
>  a  | b
> ----+----
>  10 | 10
>  10 | 20
>
> pgbash> retval=`select a,b from foo;`
> pgbash> echo $retval
> a | b ----+---- 10 | 10 10 | 20 (2 rows)

The way I usually do it in scripts is:

psql '-F<tab>' -A -t -c "query"

If there's only one field output you can drop the -F.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Janning Vygen
Date:
Subject: invalid input syntax for type bytea
Next
From: "Joshua D. Drake"
Date:
Subject: Re: [HACKERS] plPHP in core?