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

Re: SQL from shell script

From: sarlav kumar <sarlavk(at)yahoo(dot)com>
To: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
Cc: pgsqlnovice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL from shell script
Date: 2005-01-14 20:32:30
Message-ID: (view raw or whole thread)
Lists: pgsql-novice

> 4) delete from table1 where criteria1;

You want to delete these entries, I assume?

Yes, I want to delete the entries.

You could write a simple perl script that looks like:

use strict;
my $date = shift; #get from command line

my @tables = (qw/ table1 table2 table3 /); #put in your tablenames here
foreach my $tablename (@tables) {
print "create table temp1 as select * from $tablename where 
print "COPY temp1 TO '$tablename.$date.txt';\n";
print "DROP table temp1;\n";
print "DELETE FROM $tablename WHERE date='$date';\n";

This is kind of what I want to do. The only problem here is that first statement where I create temporary tables, will be selecting data from different tables based on different where clauses. Some of them even use join on tables. So I guess I can't use the foreach statement. 

Thanks a lot for the help, this definitely has given me a lead on how to proceed.

Thank you very much,



Do you Yahoo!?
 Yahoo! Mail - You care about security. So do we.

In response to

pgsql-novice by date

Next:From: John DeSoiDate: 2005-01-15 13:37:57
Subject: Re: Common question: what's wrong
Previous:From: Sean DavisDate: 2005-01-14 20:05:08
Subject: Re: SQL from shell script

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