如果我们有此类查询
INSERT INTO target_table (......)
SELECT (........)
FROM origin_table
WHERE <some conditions>
假设有一些重复项(例如,我们直接选择并插入ID),因此我们需要处理这些重复项。更有表现力的是-LEFT JOIN / IS NULL方法,还是冲突时什么都不做?
INSERT INTO target_table (......)
SELECT (........)
FROM origin_table
LEFT JOIN target_table ON target_table.id = origin_table.id
WHERE <some conditions> AND target_table.id IS NULL
或
INSERT INTO target_table (......)
SELECT (........)
FROM origin_table
WHERE <some conditions>
ON CONFLICT (id) DO NOTHING
通常哪个应该更快?