CTE incorrect generation #985
Unanswered
jurakontor
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
dear community, i am stuck with an issue and really need a help with.
I have following sql:
WITH ins AS ( INSERT INTO profile_source_on_chain (address, nick_name) VALUES ('0x72c9fb7ed19d3ce51cea5c56b3e023cd918baadf3', 'Sei Ape Club') ON CONFLICT (address, nick_name) DO NOTHING RETURNING id) SELECT id FROM ins UNION ALL SELECT id FROM profile_source_on_chain WHERE address = '0x72c9fb7ed19d3ce51cea5c56b3e023cd918baadf3' and nick_name = 'Sei Ape Club';
and i need to use bun to create same sql. This is what i am doing:
ProfileSourceOnChain is table with 3 columns: id (uuid), address , nickname varchar
Have constraint (address , nickname)
`
onChain := dto2.ProfileSourceOnChain{ Address: "address",
NickName:"nickname",
}
`
the above code will generate
(WITH ins AS ( INSERT INTO profile_source_on_chain (address, nick_name) VALUES ('0x72c9fb7ed19d3ce51cea5c56b3e023cd918baadf3', 'Sei Ape Club') ON CONFLICT (address, nick_name) DO NOTHING RETURNING id) SELECT id FROM ins) UNION ALL SELECT id FROM profile_source_on_chain WHERE address = '0x72c9fb7ed19d3ce51cea5c56b3e023cd918baadf3' and nick_name = 'Sei Ape Club';
the issue with brackets at the beginning and after FROM ins. After i execute the generated query ill get the following error:
ERROR: WITH clause containing a data-modifying statement must be at the top level
Question - how to write bun correctly to avoid those brackets. The rest for query is absolutely correct. Or this is "feature" of bun and no solution here?
thanks
Beta Was this translation helpful? Give feedback.
All reactions