M
M
Maxim Tarabrin2018-04-02 22:02:59
Python
Maxim Tarabrin, 2018-04-02 22:02:59

How to write an array of dictionaries to JSONB?

Tell me, I have formed an array of dictionaries and I want to put this array in a JSONB field. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-04-02
@padr1no

From documentation :

from psycopg2.extras import Json

data = [
    {'a': 1},
    {'b': 2},
    {'c': 3, 'z': None}
]

curs.execute("insert into mytable (jsondata) values (%s)", [Json(data)])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question