2015-11-04 184 views
0

我有一个红移表“人”在特定的列有数据像这样字符串匹配

[{"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":[]}] 

我想只提取字典/ JSON /含PIN CODE子(见下文)

{"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

你应该逃避花括号'\ {',否则它假定为像'\ W一个量词{ 2,5}'。这就是为什么它会抛出错误'“重复范围的无效内容”' – Mariano

+0

@Mario抱歉没有工作,得到了相同的错误 –

+0

任何机会,你可以创建一个小提琴? – Mariano

回答

1

我不知道如果我理解正确的,但是你可以尝试使用类似:

select * from person where attributes LIKE '%"attributeName":"PIN CODE"%'; 
+0

@IvanNo我希望子字符串{“attributeName”:“PIN码”,“attributeMetadata”:null,“attributeValue”:“32110”,“attributeImageType”:“IMG”,“attributeStatusCodes”:[]}。上面的字符串(在问题中)在单个列中 –