Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: DBI: select distinct returns same values

by Anonymous Monk
on Sep 21, 2019 at 14:19 UTC ( #11106491=note: print w/replies, xml ) Need Help??

in reply to DBI: select distinct returns same values

You might try replacing push( @all_rows, $ref ); with push( @all_rows, [ @$ref ] );.

The DBI docs for fetchrow_arrayref() say "Note that the same array reference is returned for each fetch, so don't store the reference and then use it after a later fetch.".

The [ @$ref ] effectively does a shallow clone of $ref, so you should get distinct values again. Of course, if it were me I would push $ref->[0], and then in the following foreach loop just print "$row_ref\n";.

Replies are listed 'Best First'.
Re^2: DBI: select distinct returns same values
by Anonymous Monk on Sep 21, 2019 at 14:48 UTC
    This is correct: your results-array contains three references to the same result record. That is why you see three copies of the last row. (The SQL query is presented as literal text and you have already showed us what the result is.) You must make a deep copy of each row that is returned ... or, simply skip the step of putting them into a separate array entirely and work directly from the first loop.

      AnomalousMonk: Sorry I have done againt the site rules. Iíll mend my ways, I promiss! :)

      Anonymous Monk: You are right about the push(@all_rows, [@$ref]). It really fixed the output. Thanks!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11106491]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-10-29 21:55 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (274 votes). Check out past polls.