Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

362
Vistas
How to store array of Python dicts in PostgreSQL?

I have a Django project and such array in it:

{(0,0):{'a':True,'b':False ... },(0,1):{'a':True,'b':True ... },(1,1):{'a':True,'b':False ... }... }

I need to store this array in PostgreSQL database. I thought the ArrayField could help, but I just have no idea how to declare such array. I've read https://docs.djangoproject.com/en/1.8/ref/contrib/postgres/fields/
but there was not my situation. Could you show me an example?

I'm using Django 1.8

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

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 ... }... })
over 4 years ago · Santiago Trujillo Denunciar

0

PostgreSQL has two types you may want to check out,

  • jsonb
  • hstore

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda