Skip site navigation (1) Skip section navigation (2)

Re: SQL from shell script

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: sarlav kumar <sarlavk(at)yahoo(dot)com>
Cc: pgsqlnovice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL from shell script
Date: 2005-01-14 18:46:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Is there really NO WAY you could do this in perl or java?  Database 
interfaces in these languages are easy to use and designed to avoid the 
types of stuff you are doing below.  They are generally quite flexible 
and mainstream.  For perl, see as an example.

Another way to go about the problem is to direct all your SQL queries 
into a temporary table and then use SQL COPY from that temporary table 
to a file.  You could then generate one large SQL command and push that 
through psql.


On Jan 14, 2005, at 1:36 PM, sarlav kumar wrote:

> Hi All,
> I have the following statements in my shell script:
> echo $PGPASSWORD | psql -U $USER -h $HOST -d $DBNAME -c "select * from 
> affiliate_batch where tx_dt < ' "$DATE" ' order by id; " > 
> $1$DATE.1.txt
> echo $PGPASSWORD | psql -U $USER -h $HOST -d $DBNAME -c "select * from 
> affiliate_event where dt< ' "$DATE " ' order by id; " > $1$DATE.2.txt
> I will be adding more statements in this file. I would like to know if 
> there is a way to avoid specifying the connection everytime. I would 
> like to make the connection once and then execute the set of SQL 
> statements and disconnect from the database.
> It would be great if someone could help me.
> Thanks!
> Saranya
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around

In response to


pgsql-novice by date

Next:From: sarlav kumarDate: 2005-01-14 19:12:30
Subject: Re: SQL from shell script
Previous:From: sarlav kumarDate: 2005-01-14 18:36:22
Subject: SQL from shell script

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group