davidrw has asked for the wisdom of the Perl Monks concerning the following question:

I'm having issues with a DBD::CSV (v0.22; SQL::Statement v1.14) query.. I have a GROUP BY statement that works fine on its own, but when i use it to create another table it appears that the WHERE clause is not being obeyed -- the two outputs should be identical... I'm also curious as to the "substitution iterator" warning that's thrown.
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("DBI:CSV:f_dir=."); $dbh->do("DROP TABLE dw_foo"); $dbh->do("DROP TABLE dw_counts"); $dbh->do("CREATE TABLE dw_foo ( n integer, ct integer, s text )"); $dbh->do("INSERT INTO dw_foo VALUES ( 1, 5, 'blah' )"); $dbh->do("INSERT INTO dw_foo VALUES ( 1, 6, 'stuff' )"); $dbh->do("INSERT INTO dw_foo VALUES ( 2, 5, 'blah' )"); $dbh->do("INSERT INTO dw_foo VALUES ( 2, 6, 'stuff' )"); $dbh->do("INSERT INTO dw_foo VALUES ( 2, 7, 'thing' )"); my $sql = "select n, sum(ct) as ct from dw_foo where s NOT LIKE '%a%' +group by n"; $dbh->do("CREATE TABLE dw_counts AS $sql"); doDump( $dbh->selectall_arrayref($sql) ); doDump( $dbh->selectall_arrayref("select * from dw_counts") ); sub doDump { my $aref = shift; print "TABLE:\n"; print join("\t", @$_), "\n" for @$aref; } __END__ Use of uninitialized value in substitution iterator at /home/dwestbroo +k/CPAN/lib/perl5/site_perl/5.6.1/SQL/Parser.pm line 1596. TABLE: 1 6 2 13 TABLE: 1 11 2 18

Replies are listed 'Best First'.
Re: 'create table' bug in DBD::CSV ?
by jZed (Prior) on Oct 12, 2005 at 16:07 UTC
    Sorry, it's a bug in the CREATE AS SELECT. For now you'll have to CREATE the second table manually and INSERT into it as you loop throught the SELECT on the first table. I'll look into a fix.