-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem executing Common Table Expression (WITH query) #913
Comments
When I split into 2 queries everything works well, but it would be nice to use WITH queries in many cases: const id = (await sql`insert into i18n.text default values returning id`)[0].id
const translation = Object.entries(label).map((label) => [id, ...label])
await sql`insert into i18n.translation values ${sql(translation)}` |
I can reproduce this with NodeJS runtime. Definitely looks like a bug to me. await sql`
with t as (
insert into foo values (1, 2)
)
select * from (values ${sql(translation)}) as t(lang, text)
`; and it will still produce the same error. It seems to happen whenever you do have a CTE with an insert and followed by a dynamic "values" of nested array. My guess is that the parser is mistreating the dynamic value as part of the insert statement. |
In the mean time, you can try to lift the dynamic values bit before the insert, that might get you around the problem. Something like with x as (
select * from (values ${sql(translation)}) as l(lang, text)
),
t as (
insert into i18n.text default values returning id
)
insert into i18n.translation (id, lang, text)
select id, lang, text from t cross join x
returning id
|
Hello,
Driver fails to execute WITH query as below:
Execution log:
Am I use driver properly? Query works well if executed in
cockroachdb
console. Also can bebun
related, I did not checked with other runtimes.The text was updated successfully, but these errors were encountered: