I have created in postgresql a table, using the code below :
create table spyResults (id serial not null primary key, info jsonb not null);
Now, in Python I want to insert the data into that table. I'm passing the data with the following code:
cur.execute("INSERT INTO %s(info) VALUES (%s)",[AsIs('spyResults'),json.dumps(pDoc)])
pDoc
is the Python dictionary and now I'm converting this to json
and passing to the query, but the problem is in the pDoc
dictionary we have:
datetime.datetime(2018, 3, 8, 10, 29, 49, 178285) also
when i am trying insert we are getting below error:
datetime.datetime(2018, 3, 8, 10, 29, 49, 178285) is not JSON serializable
Could please suggest how to resolve this issue. Thanks.
EDIT:its not duplicate questions as because we are not getting datetime object not as parameter, its coming with in the dictionary, we are able to insert the pDoc asis into the mongodb, i am expecting same with postgreSQL as well.