Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

One of my sql tables contains a column that has a bunch of values separated by commas. Assuming I pull the data out of that column and split at the commas, then extract one of the values that I'd like to modify, how can I rebuild the original column values with the newly modified field and save the updates back to the table?

Replies are listed 'Best First'.
(Ovid) RE: changing a certain value
by Ovid (Cardinal) on Oct 27, 2000 at 01:45 UTC
    mirod's solution is correct. However, you may wish to rethink your database design. Either adopt a multi-value database which ignores the first normal form and allows multi-value fields (like UniData or UniVerse), or extract the multiple values out to another table and have a reference to that table in your original table.

    Violating the first normal form in a database seriously interferes with maintenance and scalability. As the database grows, new programmers (and old ones) need to be aware of the multi-value fields and create new code to deal with them. If they forget, or if the new code is buggy, you can easily wind up with corrupted data.

    I realize that switching databases is probably not a viable option, so I'd recommend creating a new table.

    Just a thought... accept or disregard as you will.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

Re: changing a certain value
by mirod (Canon) on Oct 27, 2000 at 01:07 UTC

    just join the values with a comma:

    my $new_val= join ',' , @values;
RE: changing a certain value
by nop (Hermit) on Oct 27, 2000 at 04:12 UTC
    < satire>
    Hi!!!!! I have data on several 1000s multi-generation family trees stored in a MySQL database. To faciltate a simple schema, I opted for a pretty novel representation: I store each tree *graphically* in gif files, concatentate all the gifs into one big binary object, and then store the huge resulting data in a one row, one field table. It is working pretty well so far, but I am seeking the wisdom of the Monks on how to update the structure when a couple with children *divorce* then *remarry* other people. (No modules, please: prefer to code everything myself.) Thanks in advance!!!!!
    </satire>

    Sigh. I'm not bashing the anonymous monk who posted; rather, expressing my amazement at the staggering ways folks (mis)use databases.
      <satire> Your problem is the use of the GIF format for your data. If you really want to move the cutting edge of image-based storage of text-data, I suggest PNG </satire>
Re: changing a certain value
by runrig (Abbot) on Oct 27, 2000 at 01:48 UTC