I want to be able to extract text from jsonb array in a new column as text.
This is my SQL table.
Id. | ErrorCode. |
---|---|
101 | ["exit code: 1"] |
102 | ["exit code: 3"] |
103 | ["OOMKILLED"] |
This is my column definition '[]'::jsonb
I needed help understanding which select command I could use in that case. I used the query above but with no success.
Select reasons -> ' ' as TTT from my_table
I want to get these results after a select command., so I can do SQL filters like
where error = 'exit code: 1'
or where error = 'OOMKILLED'
Id. | Error |
---|---|
101 | exit code: 1 |
102 | exit code: 3 |
103 | OOMKILLED |
3
Answers
try this :
For more info about json functions see the manual
When you need check is JSONB array contains some value, just use ? operator:
https://sqlize.online/s/eW
Use
->>
to extract the first array element as text:If you don’t want to repeat the expression use a derived table: