3 ms·
Counters where the set of things you count is open-ended (e.g. words in a naive bayes classifier): INSERT INTO word_counts(word) VALUES('hello'),('world')
by pornel 13y ago
Counters where the set of things you count is open-ended (e.g. words in a naive bayes classifier):
INSERT INTO word_counts(word) VALUES('hello'),('world')
ON DUPLICATE KEY UPDATE cnt = cnt+1;
Lists where you track 'last seen':
REPLACE INTO last_login(user_id, date) VALUES(123, NOW());
With Postgres' INSERT … RETURNING this would be awesome:
INSERT INTO log(date, user_agent_id) VALUES(now(),
INSERT IGNORE INTO user_agents VALUES('Mozilla') RETURNING id)
This way I could store any long string only once, and do it atomically in one query.