sql >> Base de Datos >  >> RDS >> PostgreSQL

¿Cómo insertar JSONB en Postgresql con Python?

import json

data = [1, [2,3], {'a': [4,5]}]
my_json = json.dumps(data)
insert_query = "insert into t (j) values (%s) returning j"
cursor.execute(insert_query, (my_json,))
print (cursor.fetchone()[0])

Salida:

[1, [2, 3], {'a': [4, 5]}]