I'm trying to put an sql query in a string using pandasql pulled from AI's GPT-3. the query is SELECT * FROM netflix WHERE release_year = 2020 AND type = 'Movie' AND listed_in LIKE '%Horror% What i have at the moment is this:
sql_query = "* FROM netflix WHERE release_year = 2020 AND type = 'Movie' AND listed_in LIKE '%Horror%"
q = "SELECT" sql_query
print(pysqldf(q))
however it keeps throwing up the error unrecognized token: "'%Horror%"
I'm not really sure how to get around this?
CodePudding user response:
You have several typo errors in your query string. Here is a working query:
sql_query = "* FROM netflix WHERE release_year = 2020 AND type = 'Movie' AND listed_in LIKE '%Horror%'"
q = "SELECT " sql_query
You need a space after the SELECT
keyword, and also what follows LIKE
must be in single quotes.
CodePudding user response:
your are missing '
in the end of %Horror%
sql_query = "* FROM netflix WHERE release_year = 2020 AND type = 'Movie' AND listed_in LIKE '%Horror%'"
q = "SELECT" sql_query
print(pysqldf(q))