Skip to content
Advertisement

How should I use `json field` in where clause in postgresql?

I have a json field in postgresql table feeAmount:

I’d like to query rows whose feeAmount -> value is not null. Some rows may be null for the entire feeAmount field. some rows’ feeAmount has a json data whose value is null. They need to be excluded.

I have tried this query:

but both of the queries return the rows

how can I exclude the value: null from the query?

Advertisement

Answer

because feeAmount->'value' returns string null of json type

you can try cast feeAmount->'value' as string type before comparing.

or simple way use coalesce compare which row didn’t equal null text.

sqlfiddle

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement