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()
所以在这种情况下我能做些什么,请帮忙......