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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.