英文:
insert into table from the select query
问题
我尝试从选择查询中插入到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
如果我删除插入查询,仅运行选择查询,我可以获取到poolId
和tagId
。
任何帮助或建议都将不胜感激。
英文:
I'm trying to insert in the postgresql
table from the select query, here I have multiple joins, i successfully managed to get the data from the select query, but when i do run the insert
getting the syntax error as ERROR: syntax error at or near "select"
here below is what i tried
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
if I remove the insert query and run only select I'm getting poolId
and tagId
any helps or suggestions are really appriciated
答案1
得分: 2
You need to remove the VALUES
clause because you're not actually passing some values but a SELECT
statement:
insert into pool_tags_tag ("poolId", "tagId") SELECT p.id ...
英文:
You need to remove the VALUES
clause because you're not actually passing some values but a SELECT
statement:
insert into pool_tags_tag ("poolId", "tagId") SELECT p.id ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论