I need to pass some insert data into postgres which also contains a timestamp. I am using psycopg2 for the same.
I have tried to follow the answer here upon getting the same error as the one asked in the question: Passing a datetime into psycopg2
My code which doesn't work:
recv_data = {"datetime":datetime.datetime(2019, 12, 5, 12, 56, 34, 617607)
"temperature": 40, "humidity":80}
insert_stmt = "INSERT INTO temp_humidity (temperature,humidity,datetime) VALUES (%s,%s,%s)"
data = (recv_data["temperature"], recv_data["humidity"], recv_data["datetime"])
print(insert_stmt)
cursor.execute(insert_stmt, data)
connection.commit()
ERROR:
ERROR: current transaction is aborted, commands ignored until end of transaction block
STATEMENT: INSERT INTO temp_humidity (temperature,humidity,datetime) VALUES (42,79,'2019-12-05T05:55:45.135111'::timestamp)
Any solution would be appreciated.