I have a SQL query that fetches records between 2 dates
my_table_name='adbtable'
sql_query = '''SELECT * FROM {} WHERE date_time BETWEEN '2021/02/05' and '2021/04/28' ORDER BY date_time DESC'''.format(my_table_name)
The table name variable is successfully getting interpolated in the SQL statement and fetches the data properly.
But when I tried to add interpolation to the 2 dates am getting an error
my_table_name='adbtable'
start_date='2021/02/05'
end_date='2021/04/28'
sql_query = '''SELECT * FROM {} WHERE date_time BETWEEN {} and {} ORDER BY date_time DESC'''.format(my_table_name, start_date, end_date)
This is the error am getting.
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
But how can we cast the dates here if that's the issue?