views:

132

answers:

1

This script I'm working on is taking data from the web using python's urllib2 module and then putting it in a table. This data is basically just going to be in a table with one column and one row. How do I have it so that when I run the script it just updates the record? I don't want to make it a primary key because I'm probably going to add more columns later and the primary key probably won't be this column.

It seems like there are three ways to do this. IGNORE, REPLACE, ON DUPLICATE KEY UPDATE. I've tried IGNORE and REPLACE but they still end up creating a new record. I think it's because that column has to be primary key. I know the ON DUPLICATE KEY UPDATE requires you to make that column primary key. Is there any way to do this without making the column primary key?

+2  A: 

You can use "ON DUPLICATE KEY UPDATE" on any column with a UNIQUE index, not just the primary key column.

richardtallent