2

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?

1 Answer 1

3

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'])}
Sign up to request clarification or add additional context in comments.

4 Comments

Not really, I would like to know if I could use this kind of dict in hstore, so I could access 'type' or 'data' individually for a 'fieldname'
Maybe I would have to create four hstore column, like {'fieldname:'type'} | {'fieldname:'precision'} | {'fieldname:'width'} | {'fieldname:'data'}
you want to use the json data type if you want nested data. hstore only provides a flat data structure.
hstore can now store keys that contain arrays as values. it is a perfectly acceptable type for the question asked.

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.