开发者

Extracting values out of serialized php array in postgresql

开发者 https://www.devze.com 2023-04-11 07:41 出处:网络
Problem: one column of a table contains serialized php arrays. i\'d like to extract values of that serialized data structure with开发者_JAVA技巧out using php. i\'d need a postgres sql statement to ge

Problem:

one column of a table contains serialized php arrays. i'd like to extract values of that serialized data structure with开发者_JAVA技巧out using php. i'd need a postgres sql statement to get those values.

Example:

here's the part of the serialized datastructure, i'd need (the bold part):

... s:12:"SearchtermID";s:4:"1008"; ....

THANKS!


This will work in your example:

SELECT substring('... s:12:"SearchtermID";s:4:"1008"; ....', 's:4:"([0-9]+)"');

See the manual here and here.
You may want to provide more details ...


This my solution:

select substring((regexp_matches(db_fieldname,'("\d+")','g'))[1] from '"(\d+)"') from db_tablename
0

精彩评论

暂无评论...
验证码 换一张
取 消