Open aplatoff opened 1 month ago
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. I was able to simplify it down to something like
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.