Reidy, Ron wrote:
> 
> In the case you cite, both rows will be returned because the combination
> of columns are not unique, even though you aliased the column names,
> exactly as I did in case #3 above..

You're missing the point.  The problem is not how the rows are returned by
the database, but how the rows are inserted into the hash by DBI for
selectall_hashref().


> In Oracle, this is the expected behavior and I expect the same behavior
> when using the DBI/DBD modules.  I have not tested this in Perl, but I am
> confident this outcome will be exactly the same as when using SQL*Plus.

It's obvious you haven't tested it, since it does exactly what Ed described.


$dbh->{'FetchHashKeyName'} = 'NAME_lc';

my $data =
  $dbh->selectall_hashref(<<"  EndOfSQL", 'a');
    SELECT 5 as a, 6 as b
    FROM Dual
   UNION
    SELECT 5 as a, 7 as b
    FROM Dual
  EndOfSQL

print dump($data), "\n";


{ "5" => { a => 5, b => 7 } }


Two rows were returned by the query, but the hash only reflects one.


So, going back to the original question, what should the behavior be in this
situation, where the key field passed to selectall_hashref() is not unique?

Should the current behavior continue, where it silently throws away the
extra rows, or should it throw an error or warning?  Either way the
documentation should be updated.


Ronald


Reply via email to