Howdy:

Trying to figure out exactly what my program thinks
the problem is, but perhaps I need a fresh pair o' eyes.

My goal:  To do a basic query (count) against a database,
get that number for each column I count and put those
numbers into a new table, each under it's own column.

Background: Running PostgreSQL 7.1.3 and Perl 5.6.x

The table looks okay.  I've given it public permissions
and the like.

The errors I see when I try to run it looks like this:

[snip error]

Use of uninitialized value in concatenation (.) at 
/usr/local/home/shaunn/perl/pg_perl/sys_count.pl line 111.
Use of uninitialized value in concatenation (.) at 
/usr/local/home/shaunn/perl/pg_perl/sys_count.pl line 111.
Use of uninitialized value in concatenation (.) at 
....

[/snip error]

I'm guessing that it's complaining about the column name "AS"
or the way I'm stuffing the counts into an array and the poor
way I'm trying to parse them out and put them into separate
columns.

Again, this is just a novice trying to guess what's up.
Yeah, I know the program is big and ugly ... :)

Suggestions?  Comments (like, 'you can make the much smaller
by doing ...)?  Thanks in advance!

-X

[snip code]

#!/usr/bin/perl -w

# created 26 Jul 02 -X

# script to connect to PostgreSQL do a count
# and plug those numbers into a table for trending

use strict;
use DBI;
#use Net::SMTP;

my $dbh=DBI->connect('dbi:Pg:dbname=testdb', 'joeuser')
        or die "Can not connect: $!";


my $sql = qq| select count (type)
        from sys_dates
        where
        type = 'AC' or
        type = 'AI' or
        type = 'AM' or
        type = 'AP' or
        type = 'AS' or
        type = 'BB' or
        type = 'BD' or
        type = 'BR' or
        type = 'CA' or
        type = 'CE' or
        type = 'CP' or
        type = 'CV' or
        type = 'DC' or
        type = 'DI' or
        type = 'DM' or
        type = 'DS' or
        type = 'EA' or
        type = 'EC' or
        type = 'ED' or
        type = 'EY' or
        type = 'FE' or
        type = 'H2' or
        type = 'H3' or
        type = 'HA' or
        type = 'HB' or
        type = 'HI' or
        type = 'I3' or
        type = 'IA' or
        type = 'IC' or
        type = 'ID' or
        type = 'IN' or
        type = 'IO' or
        type = 'LD' or
        type = 'MA' or
        type = 'MB' or
        type = 'MC' or
        type = 'MD' or
        type = 'ME' or
        type = 'MN' or
        type = 'MU' or
        type = 'OD' or
        type = 'PE' or
        type = 'PV' or
        type = 'RO' or
        type = 'RU' or
        type = 'SE' or
        type = 'TE' or
        type = 'TH' or
        type = 'TM' or
        type = 'TR' or
        type = 'WA' or
        type = 'WV' or
        type = 'YA' or
        type = 'YC' or
        type = 'YD'
        group by type
        | ;

#
# test the sql and prepare to use
#

my $sth=$dbh->prepare($sql) or die "Error =", DBI::errstr;
unless ($sth->execute) {
        print"\n\tExecute failed for stmt:\n\t$sql\nError = ", DBI::errstr;
        $sth->finish;
        $dbh->disconnect;
        die "\n\t\tClean up finished\n";
}

while (@count)=$sth->fetchrow) {
$dbh->do("insert into t_sysdates_trend ("AC", "AI", "AM", "AP", "AS", "BB",
"BD", "BR", "CA", "CE", "CP", "CV", "DC", "DI", "DM", "EA", "EC", "ED",
"EY", "FE", "H2", "H3", "HA", "HB", "HI", "I3", "IA", "IC", "ID", "IN",
"IO", "LD", "MA", "MB", "MC", "MD", "ME", "MN", "MU", "OD", "PE", "PV",
"RO", "RU", "SE", "TE", "TH", "TM", "TR", "WA", "WV", "YA", "YC", "YD",
"load_date") values ( $count[0], $count[1], $count[2], $count[3], $count[4],
$count[5], $count[6], $count[7], $count[8], $count[9], $count[10],
$count[11], $count[12], $count[13], $count[14], $count[15], $count[16],
$count[17], $count[18], $count[19], $count[20], $count[21], $count[22],
$count[23], $count[24], $count[25], $count[26], $count[27], $count[28],
$count[29], $count[30], $count[31], $count[32], $count[33], $count[34],
$count[35], $count[36], $count[37], $count[38], $count[39], $count[40],
$count[41], $count[42], $count[43], $count[44], $count[45], $count[46],
$count[47], $count[48],  timestamp(now()) )" );

}

$dbh->disconnect;

[/snip code]

Reply via email to