Tag: insert update

MySQL触发器在插入/更新事件

所以我有两个这样的桌子 ext_words ————- | id | word | ————- | 1 | this | ————- | 2 | that | ————- | 3 | this | ————- ext_words_count ——————— | id | word | count | ——————— | 1 | this | 2 | ——————— | 2 | that | 1 | ——————— 我试图创build一个触发器,将: 更新ext_words_count.count时更新ext_words_count.count […]

如何在PostgreSQL中UPSERT(MERGE,INSERT … ON DUPLICATE UPDATE)?

这里一个非常常见的问题是如何做一个upsert,这就是MySQL调用INSERT … ON DUPLICATE UPDATE和标准支持作为MERGE操作的一部分。 鉴于PostgreSQL不直接支持(在第9.5页之前),你如何做到这一点? 考虑以下几点: CREATE TABLE testtable ( id integer PRIMARY KEY, somedata text NOT NULL ); INSERT INTO testtable (id, somedata) VALUES (1, 'fred'), (2, 'bob'); 现在设想你想要“插入”元组(2, 'Joe') , (3, 'Alan') ,所以新的表格内容是: (1, 'fred'), (2, 'Joe'), — Changed value of existing tuple (3, 'Alan') — Added new tuple 这就是人们在讨论一个upsert时候正在讨论的问题。 至关重要的是,任何方法在同一个表上进行多个事务的情况下都必须是安全的 – […]