Update column A with the value of column B

I want to update column B with an updated value of column A So, something like this
db
.update(characters)
.set({
normalized_name: normalize(characters.name),
})
db
.update(characters)
.set({
normalized_name: normalize(characters.name),
})
Obviously doesn't work this way, but what would be the way to do it in Drizzle?
3 Replies
Angelelz
Angelelz16mo ago
What does normalize do? Is there an equivalent function in Sql?
Meexa
MeexaOP16mo ago
Don't think so. It removes accented characters from names ø -> o for example
micaww
micaww16mo ago
you would need to use sql to do it in one call:
normalized_name: sql`SOMESQLFUNCTION(${characters.name})`
normalized_name: sql`SOMESQLFUNCTION(${characters.name})`
if you needed to do it in js then select for update to get the name, calculate new value, update in a transaction
Want results from more Discord servers?
Add your server