DatabaseError: The first argument to execute must be a string or unicode query in python DatabaseError: The first argument to execute must be a string or unicode query in python flask flask

DatabaseError: The first argument to execute must be a string or unicode query in python


You are providing a tuple to read_sql_query, while the first argument (the query) has to be a string. That's why it gives the error "The first argument to execute must be a string or unicode query".

You can pass the parameter like this:

result = "SELECT * FROM OE_TAT where convert(date,Time_IST)=?"df = pd.read_sql_query(result, connection, params=(dateval,))

Note that the use of ? depends on the driver you are using (there are different ways to specify parameters, see https://www.python.org/dev/peps/pep-0249/#paramstyle). It is possible you will have to use %s instead of ?.

You could also format the string in beforehand, like result = "SELECT * FROM OE_TAT where convert(date,Time_IST)={0}".format(dateval), however, this is not recommended, see eg here