只有在没有匹配的电子邮件的情况下,我才想进行批量插入
我试过了,但我不知道如何添加where子句。
INSERT INTO user (
'pk',
'email'
)
SELECT UNNEST(ARRAY[10, 11, 12, 13, 14, 15, 16]),
UNNEST(ARRAY['example1@example.com', 'example2@example.com', .........])
WHERE something.......
样本1:
with tbl(a,b) as (
select
UNNEST(ARRAY[10, 11, 12]),
UNNEST(ARRAY['example3@example.com', 'example4@example.com', 'example5@example.com'])
)
insert into user (pk, email)
select a, b from tbl
left join user on tbl.b = user.email
where user.email is null
样品2:
with tbl(a,b) as (
select
UNNEST(ARRAY[10, 11, 12]),
UNNEST(ARRAY['example3@example.com', 'example4@example.com', 'example5@example.com'])
)
insert into user (pk, email)
select a, b from tbl
where not exists (select 1 from user where user.email = tbl.b)