The limit is on GROUP_CONCAT. From the docs
The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024. With default limit the maximum results I could get was prod1 to prod15. After this
$dbh->do('SET SESSION group_concat_max_len = 2048');
I could get 31.
Update ; Here is the code I tested it with
#!perl use strict; use DBI; my $dbh = connect(...); $dbh->do('SET SESSION group_concat_max_len = 2048');; my $pvt_col = 'prod'; my $count = 'count'; my $table = 'prod_test'; #test data create_test_db($ARGV[0] || 10); my $s1 =<<S1; 'SUM(CASE WHEN $pvt_col IS NULL THEN $count ELSE 0 END) AS Total,' S1 my $s2 =<<S2; CONCAT( '(SUM(CASE WHEN $pvt_col = ''',$pvt_col,''' THEN $count ELSE 0 END)) AS ',$pvt_col ) S2 my $sql1 = <<SQL1; SELECT CONCAT($s1,GROUP_CONCAT(DISTINCT $s2)) FROM ( SELECT $pvt_col,count(*) AS count FROM $table GROUP BY $pvt_col WITH ROLLUP) as temptbl SQL1 my $tmp = $dbh->selectrow_array($sql1); my $sql2 = <<SQL2; SELECT $tmp FROM ( SELECT $pvt_col, count(*) AS $count FROM $table GROUP BY $pvt_col WITH ROLLUP) as temptbl SQL2 my @f = $dbh->selectrow_array($sql2); print "@f\n"; sub create_test_db { my $no = shift; #$dbh->do("DROP TABLE $table"); $dbh->do("CREATE TABLE IF NOT EXISTS $table ( id int(11) NOT NULL AUTO_INCREMENT, $pvt_col varchar(20) NOT NULL, PRIMARY KEY (id))"); $dbh->do("DELETE FROM $table"); for my $n (1..$no){ for (1..$n){ $dbh->do("INSERT INTO $table VALUES (?,?)",undef,undef,sprintf " +prod%02d",$n); } } }

poj

In reply to Re^4: return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL by poj
in thread return string from query (DBI, MySQL) got truncated when trying to generating statement dynamically for MySQL by khandielas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.