K
Kysely16mo ago
liteyear.

How can I cast a jsonb value to a float8 in query?

I have a query that has a jsonb value in the db that will always be a number, and I want to sum it. how can I change this value to a number fn.sum<number>('value') what I want is: fn.sum<number>('value'::float8)
1 Reply
koskimas
koskimas16mo ago
There's no built-in function for cast yet. For now you can do this
function float(expr: Expression<unknown>) {
return sql<number>`${expr}::float`
}

...
fn.sum<number>(float(ref('value')))
function float(expr: Expression<unknown>) {
return sql<number>`${expr}::float`
}

...
fn.sum<number>(float(ref('value')))
Like this https://kyse.link/?p=s&i=hsLrQjoDULskJqgRlupI
Want results from more Discord servers?
Add your server