-----Original Message-----
From: Ronald J Kimball [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 13, 2005 11:17 AM
To: Reidy, Ron; Avis, Ed; [email protected]
Subject: RE: selectall_hashref() when key field not unique


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().

Thanks.  I did indeed miss the point.  And, Ed is correct, fetchall_hashref 
does return only one row.  Further, it looks like only the last row of the 
UNION is kept.  This is consistent with how hashes work, is it not?

I appologize for the confussion I stirred up.


> 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



This electronic message transmission is a PRIVATE communication which contains
information which may be confidential or privileged. The information is 
intended 
to be for the use of the individual or entity named above. If you are not the 
intended recipient, please be aware that any disclosure, copying, distribution 
or use of the contents of this information is prohibited. Please notify the
sender  of the delivery error by replying to this message, or notify us by
telephone (877-633-2436, ext. 0), and then delete it from your system.

Reply via email to