1

Problem:

one column of a table contains serialized php arrays. i'd like to extract values of that serialized data structure without 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!

2
  • Take a look here Commented Oct 6, 2011 at 10:18
  • for json this will be great, for a php serialized string not so great :) Commented Oct 6, 2011 at 20:39

2 Answers 2

2

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 ...

Sign up to request clarification or add additional context in comments.

1 Comment

thanks :) this is the right trail, for my case this adaption works now. needed the name of the serialized field to filter out the right value. select substring(db-fieldname from E'"php-fieldname";s:\\d+:"(\\d+)"') from db-tablename
0

This my solution:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.