Re: How to query pgsql from a BASH script ?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
Cc: Michelle Konzack <linux4michelle(at)freenet(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to query pgsql from a BASH script ?
Date: 2005-04-04 14:56:06
Message-ID: 20050404145605.GA9422@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Janning Vygen 2005-04-04 14:58:02 invalid input syntax for type bytea
Previous Message Janning Vygen 2005-04-04 14:54:46 invalid input syntax for type bytea