I am currently trying to store two lists of json objects into my postgresql database using psycopg2 without success.
Here's a snippet of what I am trying to do...
SQL_INSERT_QUERY = """INSERT INTO table (
x,
json_list_one,
json_list_two
) VALUES (%s, %s, %s)"""
def insert_stuff(id, json_list_one, json_list_two):
values = (
id,
map(psycopg2.extras.Json, json_list_one),
map(psycopg2.extras.Json, json_list_two)
)
conn = get_connection_pool().getconn()
try:
cur = conn.cursor()
cur.execute(SQL_INSERT_QUERY, values)
conn.commit()
cur.close()
finally:
get_connection_pool().putconn(conn)
This current implementation is resulting in this error...
An exception of type ProgrammingError occured. Arguments:
('column "json_list_one" is of type json[] but expression is of type text[]\nLINE 5: ...) VALUES (\'9527d790-31dc-46fa-b683-c6fc9807c2a4\', ARRAY[\'{"h...\n ^\nHINT: You will need to rewrite or cast the expression.\n',)
Does anyone know how I am supposed to insert an array of json objects in PostgreSQL?
Thank you.