sql WITH couse + upsert = error(命令第二次不能影响行)

时间:2017-09-11 14:25:27

标签: sql postgresql

PostgreSQL的

我尝试以下一种方式从另一个表中使用UPSERT:

document.getElementById

我收到错误 WITH out_user_a AS( UPDATE user_a SET inactive = TRUE where (visit IS NULL OR purchase IS NULL) AND inactive = FALSE AND user_id = 136209 RETURNING user_guid ), new_user_a AS ( INSERT INTO user_a(user_guid, user_id, created_at, updated_at, next_update_at) SELECT DISTINCT ON (user_guid) user_guid, 136209, NOW(), NOW(), CURRENT_DATE + 60 FROM out_user_a ON CONFLICT (user_id, next_update_at) DO UPDATE SET updated_at= NOW(), inactive=FALSE RETURNING * ) SELECT * FROM new_user_a

如果我使用ON CONFLICT DO UPDATE command cannot affect row a second time代替VALUES()

,则效果很好

所以在这种情况下我能做些什么,请帮忙......

0 个答案:

没有答案