Re: SQL from shell script - Mailing list pgsql-novice

From sarlav kumar
Subject Re: SQL from shell script
Date
Msg-id 20050114203230.67424.qmail@web51306.mail.yahoo.com
Whole thread Raw
In response to Re: SQL from shell script  (Sean Davis <sdavis2@mail.nih.gov>)
List 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:

#!/usr/bin/perl
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
date='$date';\n";
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,

Saranya

 


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

pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Re: SQL from shell script
Next
From: przygoda@klub.chip.pl
Date:
Subject: Common question: what's wrong