I am trying to insert a JSON variable in python into snowflake. At first, I transformed the data frame into JSON using:
data = data.dropna(axis=0, how='all')
json_data = data.to_json(orient="records")
Then I performed the INSERT INTO query into snowflake:
conn = snowCtx.connect(
user=user,
password=password,
account=account,
database='MY_DB',
schema='PUBLIC',
warehouse='COMPUTE_WH',
role='SYSADMIN'
)
cursor = con.cursor()
query = """INSERT INTO ALL_SURVEYS_VARIANT(ALL_SURVEYS_VARIANT_ID, SURVEY_ID, SURVEY_DATA, DATE_ADDED,
DATE_UPDATED) VALUES (AUTO_INCREMENT_VARIANT_TABLE.nextval, (SELECT PARSE_JSON(%s)), %s, %s, %s)"""
if(cursor.execute(query, (json_data, nextval, now, now))):
print(filename+' JSON File INSERT query added successfully')
else:
print(filename+' JSON File INSERT query was not added')
I used cursor.execute(query, (json.dumps(json_data), nextval, now, now)).
But I keep getting the following error:
The following error occured: 002014 (22000): SQL compilation error:
Invalid expression [PARSE_JSON('[{"start":"2020-06-24T12:48:57.504+03:00","end":"2020-07-02T10:05:...,"_xform_id":535961.0}]')] in VALUES clause