Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

postgresql - Query jsonb fields in the postgres SQL

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
question from:https://stackoverflow.com/questions/65871674/query-jsonb-fields-in-the-postgres-sql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...