I’m inserting json data into a jsonb column. when I use python to perform inserts by reading from a file , the data is inserted as string but when I insert directly by assigning json to a variable(commented below) then it is inserted as an object . What am I Doing wrong below ?
import json
import psycopg2
data = open('C:\\xx\\json\. \temp1.json').read()
my_json = json.dumps(data)
connection = psycopg2.connect(user =
"xxxxx",
password =
"xxxxx",
host = "exx",
port = "54xx",
database =
"dxxx")
cursor = connection.cursor()
insert_query = "insert into gna (data) values (%s)"
cursor.execute(insert_query, (my_json,))
connection.commit()
count = cursor.rowcount
print (count,
"Record inserted successfully into xx table")