Below the Radar
Below the Radar

Reputation: 7635

How to store a python dict in Postgresql hstore

I would like to store this kind of dict in hstore. Is it supported by hstore?

dict= {'fieldnames':['type', 'precision', 'width', 'data']}

If not, is there a way to flatten that structure to make it supported by hstore?

Upvotes: 2

Views: 3181

Answers (1)

mjallday
mjallday

Reputation: 10082

What you'd want to do is write a wrapper on the field that will stringify nested data on writes and the de-serialize that info when you read it back.

e.g. you want to store it like this:

{"fieldnames" : "['type', 'precision', 'width', 'data']"}

you can do it using json.dumps:

{"fieldnames" : json.dumps(['type', 'precision', 'width', 'data'])}

Upvotes: 3

Related Questions