Thread: Running queries from scripts.

Running queries from scripts.

From
"DalTech - Continuing Technical Education"
Date:
I was wondering if anyone could help me out with the syntax of running queries from a unix script.
 
psql -c select 'I am a dummy' -d dbname  - never seems to work.  I've tried variations on the command line, but to no success.
 
Does the -c option work?
 
Cheers,
Christopher Currie

__________________________________
Dalhousie: DalTech - CTE
Visit our Web site at http://www.cte.dal.ca
(902) 494-6079
(800) 565-1179

Re: Running queries from scripts.

From
Margarita Barvinok
Date:
Hi,

It works for me, for example, this way:
athens% psql -d template1 -c "select datname from pg_database" datname  
-----------template1postgresbiologytest
(4 rows)
Hope this helps,
-Rita


On Thu, 6 Jul 2000, DalTech - Continuing Technical Education wrote:

> I was wondering if anyone could help me out with the syntax of running queries from a unix script.
> 
> psql -c select 'I am a dummy' -d dbname  - never seems to work.  I've tried variations on the command line, but to no
success.
> 
> Does the -c option work?
> 
> Cheers,
> Christopher Currie
> 
> __________________________________
> Dalhousie: DalTech - CTE
> Visit our Web site at http://www.cte.dal.ca
> (902) 494-6079
> (800) 565-1179
> 

--------------------------------------------------------
Margarita Barvinok                University of Michigan
System Administrator II           Department of Biology
brita@umich.edu
---------------------------------------------------------



Re: Running queries from scripts.

From
"DalTech - Continuing Technical Education"
Date:
> It works for me, for example, this way:
> athens% psql -d template1 -c "select datname from pg_database"

Thanks, I feel a little sheepish at not trying it with quotes around the
query, but the manuals don't mention that you have to enclose the query in
quotes when you use the -c option.

-Christopher Currie