thanks Chris !<div><br></div><div>We solved it essentially the same way it looks like.</div><div><br></div><div>Jay<br><br><div class="gmail_quote">On Thu, Mar 1, 2012 at 1:57 PM, Chris Hamilton <span dir="ltr"><<a href="mailto:cjhamil@gmail.com">cjhamil@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Assuming that all keys at a given depth of the hash structure are<br>
unique (probably a big assumption with city names in a state), the<br>
attached script example should probably do what you need (assuming I'm<br>
correctly understanding your problem and you're trying to figure out<br>
how to iterate through the hash structure and do the necessary inserts<br>
with the correct parentIDs).  If I'm wrong about which problem you're<br>
having I apologize, but hopefully this provides some insight.<br>
<br>
Thanks,<br>
-Chris<br>
<div class="HOEnZb"><div class="h5"><br>
On Thu, Mar 1, 2012 at 1:14 PM, Jay Strauss <<a href="mailto:me@heyjay.com">me@heyjay.com</a>> wrote:<br>
> Hi, yes (unfortunately) it all has to go in the same table.<br>
><br>
> I'm using a vendor supplied data model, with a generic structure like;<br>
><br>
> ID NAME ParentID<br>
><br>
> Although, even if I could break it up into separate tables I'd still need<br>
> the keys<br>
><br>
><br>
> On Thu, Mar 1, 2012 at 1:11 PM, Chris Hamilton <<a href="mailto:cjhamil@gmail.com">cjhamil@gmail.com</a>> wrote:<br>
>><br>
>> Just out of curiosity, is there a strong need to put all of this data<br>
>> into the same table?  At least with your example data it seems like<br>
>> the hierarchy is better managed through separate tables for city,<br>
>> state, and zip (with a 1:many relationship from state to city, and<br>
>> then from city to zip).  In that form it would be easy enough to<br>
>> create the ID's and tie them up as you iterate through your hash keys.<br>
>>  Just a thought.<br>
>><br>
>> -Chris<br>
>><br>
>> On Thu, Mar 1, 2012 at 12:58 PM, Jay Strauss <<a href="mailto:me@heyjay.com">me@heyjay.com</a>> wrote:<br>
>> > Imran,<br>
>> ><br>
>> > Thanks.  I'm ok with building a tree, currently I'm using a hash. I just<br>
>> > don't know how to unwind the tree and assign the proper ID and parent<br>
>> > ID.<br>
>> ><br>
>> > Jay<br>
>> ><br>
>> ><br>
>> > On Thu, Mar 1, 2012 at 12:51 PM, imran javaid <<a href="mailto:imranjj@gmail.com">imranjj@gmail.com</a>> wrote:<br>
>> >><br>
>> >> One option would be use a tree data structure. Take a look at<br>
>> >> Tree::Simple. You will have USA in the first level, states in the<br>
>> >> second,<br>
>> >> cities in the third, and zip codes in the 4th (and then whatever else<br>
>> >> below<br>
>> >> that).<br>
>> >><br>
>> >> -imran<br>
>> >><br>
>> >> On Thu, Mar 1, 2012 at 12:40 PM, Jay Strauss <<a href="mailto:me@heyjay.com">me@heyjay.com</a>> wrote:<br>
>> >>><br>
>> >>> Hi all,<br>
>> >>><br>
>> >>> I have some data like:<br>
>> >>> CITY|STATE|ZIP<br>
>> >>> SCHAUMBURG|IL|60194<br>
>> >>> MATTESON|IL|60443<br>
>> >>> WARRENTON|OR|97146<br>
>> >>> MOUNTAIN HOME|AR|72653<br>
>> >>> FORT WORTH|TX|76107<br>
>> >>> CLEVELAND|MS|38732<br>
>> >>> WATERTOWN|SD|57201<br>
>> >>> GRAND CHUTE|WI|54913<br>
>> >>><br>
>> >>> I want to load it into a relational database in such a way that I have<br>
>> >>> the proper keys to build a hierarchy.<br>
>> >>><br>
>> >>> so for example:<br>
>> >>> ID Name ParentID<br>
>> >>> 0 USA<br>
>> >>> 1 IL 0<br>
>> >>> 2 SCHAUMBURG 1<br>
>> >>> 3 60194 2<br>
>> >>> 4 MATTESON 1<br>
>> >>> 5 60443 4<br>
>> >>> 6 OR 0<br>
>> >>> 7 WARRENTON 6<br>
>> >>> 8 97146 7<br>
>> >>> ...<br>
>> >>><br>
>> >>> I'm not sure of a good way to do this.<br>
>> >>><br>
>> >>> I read the data an built a hash like:<br>
>> >>> USA => {IL => {SCHAUMBURG => {60194 => 0},<br>
>> >>>       MATTESON   => {60443 => 0}},<br>
>> >>> OR => {WARRENTON  => {97146 => 0}}<br>
>> >>> ...<br>
>> >>> };<br>
>> >>><br>
>> >>> I can't think of a good way to look through it and assign the keys.<br>
>> >>><br>
>> >>> Maybe someone has done this in the past and has an elegant solution?<br>
>> >>><br>
>> >>> Thanks<br>
>> >>> Jay<br>
>> >>><br>
>> >>> _______________________________________________<br>
>> >>> Chicago-talk mailing list<br>
>> >>> <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> >>> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
>> >><br>
>> >><br>
>> >><br>
>> >> _______________________________________________<br>
>> >> Chicago-talk mailing list<br>
>> >> <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> >> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > Chicago-talk mailing list<br>
>> > <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> > <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
>> _______________________________________________<br>
>> Chicago-talk mailing list<br>
>> <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Chicago-talk mailing list<br>
> <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
</div></div><br>_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></blockquote></div><br></div>