I searched around the dbi docs and googled around but could not find if there was a (dbi) native way of building up a hash of lists. The closest I can think of is fetchall_hashref but that overwrites the results, only giving me whatever the last pair was. To clarify, my table is a list of pairs of something like "id, tag". I wish to group all rows by id and retu a hash where the key is the id, and the "value" is a (ref to) the list of all its tags. So in the case of:
id1, tag1
id1, tag2
id2, tag3
id2, tag1
I want to get:
{'id1' => ['tag1', 'tag2'],
'id2' => ['tag3', 'tag1'] }
Is this possible? If not, what is the best (most efficient) way to do this non-natively? The obvious approach would be to just do a fetchall_* + push() combo, but is there a better way?
Recent Questions...
ما را در سایت Recent Questions دنبال میکنید
برچسب:
نویسنده: استخدام کار
بازدید: 184
تاريخ: سه
شنبه
25 خرداد
1395 ساعت: 6:28