Reputation: 169
I'm trying fetch the maximum date from the jsonb column.
I'm getting this below error..
------------------------------------
id | obj_value(jsonb)
------------------------------------
1 | {"value": [{"date": "2020-12-2020"}]}
------------------------------------
2 | {"value": [{"date": "2020-12-2019"}]}
---------------------------------
3 | {"value": [{"date": "2020-12-2018"}]}
---------------------------------
here is the SQL query
SELECT max(obj_value->'value'->0->'effectiveDate')
FROM public.tbl_data
where obj_value->'value'->0->>'effectiveDate' <= TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD')
I'm getting this below error..
ERROR: function max(jsonb) does not exist
LINE 1: SELECT max(obj_value->'value'->0->'effectiveDate')
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 8
Upvotes: 0
Views: 763
Reputation: 1568
->
operator returns JSONB
type,
->>
retuns TEXT
type.
You should use ->>
and then cast to a type you need
Upvotes: 1