CodeBug
CodeBug

Reputation: 1667

insert into table from the select query

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

Upvotes: 0

Views: 57

Answers (1)

cdrrr
cdrrr

Reputation: 1114

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 ...

Upvotes: 2

Related Questions