簡體   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