Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Some Postgres In Perl Code

DZone's Guide to

Some Postgres In Perl Code

·
Free Resource
// description of your code here


#!/usr/bin/perl

use DBI;

&GetTables;

my $dbh = DBI->connect("dbi:Pg:dbname=emery", "openbasin","rx9km7",{ RaiseError => 1, AutoCommit => 1 });
open FH, ">bigDel.sql";

foreach(@tables){
    my $sth =  $dbh->prepare("SELECT data_date FROM $_" );
    $sth->execute;

    while (@row=$sth->fetchrow_array){
        if($row[0] =~ /(\d\d\d\d-\d\d-\d\d) 23:59:\d\d/){
            my $nsth = $dbh->prepare("SELECT COUNT(*) AS count FROM $_ WHERE data_date = '$1 00:00:00'" );
            $nsth->execute || die "new died.\n";
            @row_ary  = $nsth->fetchrow_array;
            if($row_ary[0]){
                $dupe_tables{$_} = 1;
                print FH "DELETE FROM $_ WHERE data_date = '$1 23:59';\n";
            }
        }
    }
    $sth->finish;
}

close FH;
$dbh->disconnect;

print "The following tables have dupes:\n";
foreach(keys %dupe_tables){
    print "$_\n";
}

sub GetTables{
@tables = qw/
s400_day
behp_day
blac_day
blue_day
/;}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}