so I am trying to update the JSON file using this particular query, but everytime i run this, it throws the error and my database isnot updated.
cursor = connection.cursor()
updated_data = {
"Name": "John",
"Age": "53",
"SSN": "374875430"
}
row_id = 1
try:
updated_json_data = json.dumps(updated_data)
update_query = """
UPDATE my_table
SET json_data = %s
WHERE id = %s;
"""
cursor.execute(update_query, (updated_json_data, row_id))
connection.commit()
print("JSON data updated successfully!")
except (Exception, psycopg2.DatabaseError) as error:
connection.rollback()
print("Error while updating JSON data:", error)
finally:
cursor.close()
connection.close()
First I thought the issue is with forming the connection with DB, but that is not the case. For now I am not able to identify what could be the issue and would be grateful for your help.