No problem at all for DBI. I ran your SQL without problem in the postgres dialect:

#!/bin/env perl use strict; use warnings; use Data::Dumper; use DBI; # table my_table; # first | middle | last # -------+--------+------ # joe | john | sean # joe | john | sean # joe | john | sean # pet | joe | sean # pet | zoe | joe # ken | zoe | joe # (6 rows) # (picking up dsn from environment:) my $dbh = DBI->connect or die "oops - no db connection\n"; $dbh->{RaiseError} = 1; my $sql = " with data_count as ( select sum(case when FIRST = 'joe' then 1 else 0 end) as a_count , sum(case when MIDDLE = 'joe' then 1 else 0 end) as b_count , sum(case when LAST = 'joe' then 1 else 0 end) as c_count from my_table where FIRST like 'joe%' or MIDDLE like 'joe%' or LAST like 'joe%' ) select 'Search by: ' || 'joe' union all select 'Found ' || cast(a_count as integer) || ' ' || 'joe' +|| ' for First' from data_count union all select 'Found ' || cast(b_count as integer) || ' ' || 'joe' +|| ' for Middle' from data_count union all select 'Found ' || cast(c_count as integer) || ' ' || 'joe' +|| ' for Last' from data_count " ; # ?column? # ------------------------ # Search by: joe # Found 3 joe for First # Found 1 joe for Middle # Found 2 joe for Last # (4 rows) my $sth = $dbh->prepare($sql); $sth->execute() or die "SQL Error: $DBI::errstr\n"; my $data = $sth->fetchall_arrayref({}); warn Dumper $data;

which results in the expected output (proving that neither DBI nor the general SQL is at fault):

$VAR1 = [ { '?column?' => 'Search by: joe' }, { '?column?' => 'Found 3 joe for First' }, { '?column?' => 'Found 1 joe for Middle' }, { '?column?' => 'Found 2 joe for Last' } ];

(A further variant with placeholders also gave no problem (in postgres). )

What database are you using? What is the error you get? Is there anything in the database logfile?


In reply to Re: Undefined value from DBI by erix
in thread Undefined value from DBI by Anonymous Monk

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.