我使用psql,我有一张桌子,看起来像这样:
id | dashboard_settings
-----------------------
1 | {"query": {"year_end": 2018, "year_start": 2015, "category": ["123"]}}有许多行,但是对于每一行,“类别”值是一个包含一个整数的数组(以字符串格式)。
有什么方法可以“解压缩”类别对象吗?所以它只有123作为整数?
我试过,但没有成功:
SELECT jsonb_extract_path_text(dashboard_settings->'query', 'category') from table这将返回:
jsonb_extract_path_text | ["123"]当我想:
jsonb_extract_path_text | 123发布于 2019-12-10 15:45:03
您需要使用数组访问操作符,其简单名称是->>,后面跟着数组索引:
select jsonb_extract_path(dashboard_settings->'query', 'category') ->> 0
from the_table另一种选择是:
select dashboard_settings -> 'query' -> 'category' ->> 0
from the_tablehttps://stackoverflow.com/questions/59270807
复制相似问题