我试图运行条件插入语句,但遇到问题。
声明如下:
insert into category_content (category_id, content_id, content_type_id, priority) (select 29, id, 1, 1 from article where blog_id = 80)
where not exists(
select * from category_content where category_id = 29 and firstname in (select id from article where blog_id = 80)
);
这是我得到的错误:
ERROR: syntax error at or near "where"
LINE 2: where not exists(
^
********** Error **********
ERROR: syntax error at or near "where"
SQL state: 42601
Character: 153
最佳答案
不能有两个where子句,只能有一个:
insert into category_content (category_id, content_id, content_type_id, priority)
select 29, id, 1, 1
from article
where blog_id = 80
and not exists(select *
from category_content
where category_id = 29
and content_id in (select id
from article
where blog_id = 80));
关于sql - Postgresql中的条件插入语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44577197/