在向查询中插入数据时,如何直接使用变量代替字符串?import pymysql
import json
# Connect to the database
conn = pymysql.connect(host='localhost',
user='test',
password='br',
db='testing')
cur = conn.cursor()
json_data = json.loads(open("res.json").read())
# currently this is the query I want to execute
query = """INSERT INTO RF.candidate (
first_name, last_name, phone, email,
social, website
) VALUES (
'David', 'N', '["+1 917 547 7813", "+1 917 547 7823"]',
'["testing@gmail.com"]', '["fb.com/rtr"]', '["google.com", "sris.com"]',
'{"Degree": {"MBA": {"Majors": [""]}}}',
);"""
cur.execute(query)
# datatypes:
# first_name : varchar
# last_name : varchar
# phone : json
# email : json
# social : json
# website: json
# education: json
电子邮件地址数据位于JSON_DATA变量中,print(json_data['email'])
# returns
["testing@gmail.com"]
email_array = json.dumps(json_data['email'])
现在我想在sql查询email列中传递变量email_array,而不是像上面那样在查询变量中手动编写json列表?
我怎么用Python做呢?