K
Kysely•12mo ago
bombillazo

Use JSON key as text

Hello, I am using the following syntax to fetch data in a JSONB column:
.select((eb) => [
'id',
eb
.ref('jsonb_col', '->')
.key('lvl_1')
.key('value')
.as('my_val'),
...
.select((eb) => [
'id',
eb
.ref('jsonb_col', '->')
.key('lvl_1')
.key('value')
.as('my_val'),
...
This returns my_val as a json value which is equivalent to using ->, how can I retrieve the data using the Postgres ->> operation that returns the data as TEXT?
Solution:
aah, i had to change the first -> to ->>, doh!
Jump to solution
2 Replies
Solution
bombillazo
bombillazo•12mo ago
aah, i had to change the first -> to ->>, doh!
Igal
Igal•11mo ago
Hey 👋 If you expect it to be returned as string, make sure you use $castTo<string>() or something.
Want results from more Discord servers?
Add your server