View Single Post

   
  #8 (permalink)  
Old 04-08-2008, 09:25 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: How to query pgsql from a BASH script ?

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.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFCUVWFY5Twig3Ge+YRAjVzAJ4wBiJSkTkBT2B82uf75u 9M7H36dgCg29ZJ
4whby4AoQ6oyE9cPkslxinE=
=0zMa
-----END PGP SIGNATURE-----

Reply With Quote