繁体   English   中英

Postgresql中的条件插入语句

[英]Conditional insert statement in postgresql

我正在尝试运行条件插入语句,但遇到了问题。 这里的声明:

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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM