Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- Conditional mysql insert question - how to prevent duplicates


brotherhood_of_LAN - 10:39 pm on Aug 3, 2011 (gmt 0)


Indeed, I've never considered 1000 byte keys in practice, even if it's multi-byte text encoding...

You could probably get away with a 16 byte PRIMARY key by adding a BINARY(16) column for MD5 values.

INSERT IGNORE tablename (hash,term,url) VALUES (UNHEX(MD5('$term$url')),'$term','$url') ON DUPLICATE KEY UPDATE countercolumn = countercolumn + 1


// added

If you were to use MD5, you'd probably want to turn the $term URL to lowercase if case is unimportant for that field, as it would generate separate MD5's for lower and upper case.

[edited by: brotherhood_of_LAN at 10:43 pm (utc) on Aug 3, 2011]


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4347419.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com