解析json对象键值postgresql的文本
我在表列中维护了以下类型的对象。我已尝试解析此对象以获取此键“解析json对象键值postgresql的文本,sql,postgresql,Sql,Postgresql,我在表列中维护了以下类型的对象。我已尝试解析此对象以获取此键“1075852262”的值,该键具有此值“Event=\'13\'Description=\”(EMOVIES r8)\”………” 我编写的SQL是: select o_id, array_to_json(array[to_json(o_propertyblob1::json->'1075852262')])->>0 from tableone; 结果如下: Event="13" Descri
1075852262
”的值,该键具有此值“Event=\'13\'Description=\”(EMOVIES r8)\”………
”
我编写的SQL是:
select o_id, array_to_json(array[to_json(o_propertyblob1::json->'1075852262')])->>0 from tableone;
结果如下:
Event="13" Description="(EMOVIES r8)" SourcePath="" Comment="" CreateTime="2010-10-28 12:55:44" Creator="krima03" HistoryId="{FBA00637-9F62-4230-BA49-9A6D61485CD4}" SourceId="" SourceShortId="",Event="2" Description="" SourcePath="" Comment="" CreateTime="2010-03-08 15:49:06" Creator="" HistoryId="{FF9AEF73-9E12-413F-A340-A2011B81BC12}" SourceId="" SourceShortId="",Event="11" Description="" SourcePath="" Comment="" CreateTime="2010-08-07 13:54:20" Creator="daspi02" HistoryId="{FB4C69B6-6E00-45C2-B8CF-DE32CEF89F34}" SourceId="" SourceShortId=""
现在,我只想从中提取说明值,即(EMOVIES r8)
。我怎样才能做到这一点呢?使用正则表达式的方法可能就是您想要的。我用以下方法解决了你的案子
with data as
(
select 'Event="13" Description="(EMOVIES r8)" SourcePath="" Comment="" CreateTime="2010-10-28 12:55:44" Creator="krima03" HistoryId="{FBA00637-9F62-4230-BA49-9A6D61485CD4}" SourceId="" SourceShortId="",Event="2" Description="" SourcePath="" Comment="" CreateTime="2010-03-08 15:49:06" Creator="" HistoryId="{FF9AEF73-9E12-413F-A340-A2011B81BC12}" SourceId="" SourceShortId="",Event="11" Description="" SourcePath="" Comment="" CreateTime="2010-08-07 13:54:20" Creator="daspi02" HistoryId="{FB4C69B6-6E00-45C2-B8CF-DE32CEF89F34}" SourceId="" SourceShortId=""' colname
)
select substring(colname from '%Description="#"[A-Za-z0-9 \(\)]+#"%' for '#') from data;
带有正则表达式的子字符串工作起来很有魅力!
with data as
(
select 'Event="13" Description="(EMOVIES r8)" SourcePath="" Comment="" CreateTime="2010-10-28 12:55:44" Creator="krima03" HistoryId="{FBA00637-9F62-4230-BA49-9A6D61485CD4}" SourceId="" SourceShortId="",Event="2" Description="" SourcePath="" Comment="" CreateTime="2010-03-08 15:49:06" Creator="" HistoryId="{FF9AEF73-9E12-413F-A340-A2011B81BC12}" SourceId="" SourceShortId="",Event="11" Description="" SourcePath="" Comment="" CreateTime="2010-08-07 13:54:20" Creator="daspi02" HistoryId="{FB4C69B6-6E00-45C2-B8CF-DE32CEF89F34}" SourceId="" SourceShortId=""' colname
)
select substring(colname from '%Description="#"[A-Za-z0-9 \(\)]+#"%' for '#') from data;