[Fixed]-How to store array of Python dicts in PostgreSQL?

1👍

JSON field should be perfect for you. https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#querying-jsonfield

from django.contrib.postgres.fields import JSONField
from django.db import models

class ModelName(models.Model):
    json_data = JSONField()

Now to save the data,

ModelName.objects.create(json_data={(0,0):{'a':True,'b':False ... },(0,1):{'a':True,'b':True ... },(1,1):{'a':True,'b':False ... }... })

0👍

PostgreSQL has two types you may want to check out,

Both have overlapping functionality. JSON is part of the SQL 2016 spec though; hstore while having some advantages on JSONB is a PostgreSQL thing

Leave a comment