in reply to DBI:CSV SQL parsing problem

Workaround:
my $sth = $dbh->prepare("SELECT AVG(col2), AVG(col3) FROM mydata.csv") +; $sth->execute(); my @avgs = $sth->fetchrow_array(); my $avg = $avgs[0] + $avgs[1];

Replies are listed 'Best First'.
Re^2: DBI:CSV SQL parsing problem
by jZed (Prior) on Nov 05, 2007 at 17:00 UTC
    Something like that might work. OTOH, I'm not totally sure what AVG(col1 +col2) should produce or whether it would be same as what you suggest. For example, since NULLs are eliminated, the two columns may have a different Count.
Re^2: DBI:CSV SQL parsing problem (NULL)
by tye (Sage) on Nov 05, 2007 at 17:00 UTC

    Note that this gives different results if ever only one of col2 and col3 are NULL.

    - tye        

      No worries there, all columns have the same number of (non NULL) values.
Re^2: DBI:CSV SQL parsing problem
by rlewisuk (Initiate) on Nov 05, 2007 at 19:38 UTC
    Thanks ikegami
    This might be an option. I have tried
    SELECT AVG(col2) + AVG(col3)...
    Without success. If I use
    my $avg = $avgs[0] + $avgs[1];
    I'll first have to parse the SELECT statement for +,-,* and / and replace with commas and do the operation afterwards, but it certainly seems doable.