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

I have a database application using Class::DBI. I use it to insert and retrive records. Recently, each existing record may have an additional field available for inserting and retriving. How I can do this, harmlessly? I have already make a new template (using Template) for displaying the additional field.

--Artist

Replies are listed 'Best First'.
Re: Database Re-Insert
by adrianh (Chancellor) on Feb 27, 2006 at 01:12 UTC
    I have a database application using Class::DBI. I use it to insert and retrive records. Recently, each existing record may have an additional field available for inserting and retriving. How I can do this, harmlessly? I have already make a new template (using Template) for displaying the additional field.

    Erm. You add the new column to your table. If you're not using something like Class::DBI::Loader add the new column to your Class::DBI subclass. Done.

    What's the problem? :-)

      The problem is the question, before I start. Is it going to overwrite the data for existing primary keys? I want the overwrite, instead of rejection or duplication. I like to update existing records with the new data.
      --Artist
        The problem is the question, before I start. Is it going to overwrite the data for existing primary keys? I want the overwrite, instead of rejection or duplication. I like to update existing records with the new data.

        Almost all databases provide some mechanism for updating tables without clearing them. Take a look at your local database's documentation. For MySQL and PostgreSQL take a look at ALTER TABLE.

        (and of course be sure to take backups before hand.)

Re: Database Re-Insert
by randyk (Parson) on Feb 27, 2006 at 15:42 UTC
    If this is a question on how to add a new column to an existing table, you can use ALTER TABLE. Backing things up would be a good idea in case something goes wrong.