I have a variable db which is read from environment file. I am tryin gto use it inside a cursor execution statements as below.
config={}
with open('environment.yml','r') as f:
config = yaml.safe_load(f)
db = config['database_name']
result = cur.execute("TRUNCATE TABLE {db}.my_table")
result = cur.executemany('INSERT INTO {db}.my_table\
(id, description,code)\
VALUES (?, ?, ?)',
list(tuple(row) for row in co.values))
I have tried using however not sure if this is the right way to include variable in string.
queryString = f'''TRUNCATE TABLE {env_db}.smartselect_qc_ordercodes'''
result = cur.execute("TRUNCATE TABLE {db}.my_table")
result = cur.executemany('INSERT INTO {db}.my_table\
(id, description,code)\
VALUES (?, ?, ?)',
list(tuple(row) for row in co.values))
f"TRUNCATE TABLE {db}.my_table"