This is my first time to execute custom SQL directly, How to add dynamic string value inside the sql query? I try some of the example and docs from django sql but still not working.
def insert_sql():
dn = datetime.today() - timedelta(days=1)
dn = str(dn)
date_input = datetime.strptime(dn[:-7],'%Y-%m-%d %H:%M:%S')
date_input= date_input.strftime('%Y-%m-%d')
sql = '''INSERT INTO table name(
........................
more sql here
WHERE item IS NOT NULL AND disc <> '-'
AND date= '{date}' '''
with connections['db_2'].cursor() as cursor:
cursor.execute(sql)
row = cursor.fetchone()
return row
The error is:
django.db.utils.ProgrammingError: syntax error at or near "{"
LINE 485: AND date= {date}
please help me. Thnank You!