我有一个红色表“人”,其中特定列的数据类似于此
[{"attributeName":"name","attributeMetadata":null,"attributeValue":"KitchenAid - 7-Speed Hand Mixer - White","attributeImageType":"PRODUCT","attributeStatusCodes":[]},
{"attributeName":"title","attributeMetadata":null,"attributeValue":"KitchenAid","attributeImageType":"PRODUCT","attributeStatusCodes":[]},
{"attributeName":"address","attributeMetadata":null,"attributeValue":"address","attributeImageType":"PRODUCT","attributeStatusCodes":[]},
{"attributeName":"PIN CODE","attributeMetadata":null,"attributeValue":"32110","attributeImageType":"IMG","attributeStatusCodes":[]}]
我想只提取包含PIN CODE
的字典/ json / substring(见下文)
{"attributeName":"PIN CODE","attributeMetadata":null,"attributeValue":"32110","attributeImageType":"IMG","attributeStatusCodes":[]}
我尝试了以下查询,它发出以下错误
select distinct regexp_substr(attributes,'.*({.*?"attributeName":"PIN CODE".*?}).*') from person ;
ERROR: Invalid content of repeat range
DETAIL:
-----------------------------------------------
error: Invalid content of repeat range
code: 8002
context: T_regexp_init
query: 528401
location: funcs_expr.cpp:130
process: query2_40 [pid=12603]
-----------------------------------------------
我猜问题是因为单个列中有多个attributeName
而发生的。是他们达到预期结果的方法。
答案 0 :(得分:1)
我不确定我是否理解正确,但您可以尝试使用LIKE:
select * from person where attributes LIKE '%"attributeName":"PIN CODE"%';