You need to read about database normalisation.

Essentially, what you have here is not a large complicated data structure containing many fields, but a very simple data structure containing very few, as so:

table stats ( jobid INT, try INT, item VARCHAR(255), value VARCHAR(255), # or maybe TEXT or equivalent PRIMARY KEY (jobid, try) );

Or similar. You would then be able to retrieve all the contents of the hash by:

select item, value from stats where jobid=273118 and try=1

It also allows you to get nice aggregate stats as so:

select owner, count(*) as n from stats where try=1 group by owner orde +r by n
Which would give you a nicely sorted list of all the different owners in all the jobs, and a count of how many jobs they own.

Even better, its trivial to code for to load and unload from the hash..

foreach (keys %hash) { $dbi->do('insert into stats (jobid,try,item,value) (?,?,?,?)',$job +id, $try, $_, $hash{$_}); }
etc.

Read a good book on SQL, or if you alreayd know SQL decently, on database normali|sz|ation and what it means for your data structures.

Create them well, and the database will end up doing all the work for you.


In reply to Re: MySQL Table Creation using DBI by PhiRatE
in thread MySQL Table Creation using DBI by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.