dsf_2
dsf_2
DTDrizzle Team
Created by dsf_2 on 7/31/2024 in #help
Updating multiple rows causes type error
I'm following the guide posted here https://orm.drizzle.team/learn/guides/update-many-with-different-value regarding updating multiple rows at once. My data is similar, but not the same:
const inputs = [
{
id: 9,
order: 2,
},
{
id: 10,
order: 1,
},
];
const inputs = [
{
id: 9,
order: 2,
},
{
id: 10,
order: 1,
},
];
The raw output is:
{
sql: '(case when "routes"."id" = $1 then $2 when "routes"."id" = $3 then $4 end)',
params: [ 9, 2, 10, 1 ]
}
{
sql: '(case when "routes"."id" = $1 then $2 when "routes"."id" = $3 then $4 end)',
params: [ 9, 2, 10, 1 ]
}
Unfortunately, this causes a type error when being submitted:
Database Error: error: column "order" is of type integer but expression is of type text
Database Error: error: column "order" is of type integer but expression is of type text
I assume this is because the sql is being converted to something like this:
case when "routes"."id" = 9 then "2"
case when "routes"."id" = 9 then "2"
therefore it's being recognized as a string whenever it's submitted to the database. But I could be wrong. Is it possible to cast this value somehow or otherwise inform Drizzle that it's supposed to be an integer and not a string?
12 replies