postgresql 从选择查询插入表

vuktfyat  于 2023-05-22  发布在  PostgreSQL
关注(0)|答案(1)|浏览(141)

我试图从选择查询中插入postgresql表,这里我有多个连接,我成功地从选择查询中获取数据,但当我运行insert时,语法错误为ERROR: syntax error at or near "select"
下面是我尝试的

insert into pool_tags_tag ("poolId", "tagId") values (
                    select p.id as "poolId", t3.id as "tagId" from tag t3, pool p where t3.title in 
                    (select q.topic as "questionTopic" from question q 
                    join question_experience qe on qe."questionId" = q.id 
                    join "question_jobRole" qjr ON qjr."questionId" = q.id
                    join tag t on t.id = qjr."tagId"
                    join tag t2 on t2.id = qe."tagId" 
                    where t.title = 'FE' and t2.title = 'FRESHER') 
                    and p.id=144 limit = 1) ON CONFLICT ("poolId", "tagId") DO nothing

如果我删除插入查询并只运行select,我将得到poolIdtagId
任何帮助或建议真的很感激

xmakbtuz

xmakbtuz1#

你需要删除VALUES子句,因为你实际上没有传递一些值,而是传递了一个SELECT语句:
insert into pool_tags_tag ("poolId", "tagId") SELECT p.id ...

相关问题