[英]Query jsonb fields in the postgres SQL
I'm trying fetch the maximum date from the jsonb column.我正在尝试从 jsonb 列中获取最大日期。
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这是 SQL 查询
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
->
operator returns JSONB
type, ->
运算符返回JSONB
类型,
->>
retuns TEXT
type. ->>
返回TEXT
类型。
You should use ->>
and then cast to a type you need您应该使用
->>
然后转换为您需要的类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.