1
import pandas as pd
import sqlalchemy as sa

query = "SELECT * FROM students WHERE name IN :name"
t = as.text(query)
pd.read_sql(t, con=conn, params={'name': ['Ravi', 'Rami']}

This is what I tried but it results in a syntax error. Is there a workaround to accept a list as a named parameter with the IN operator?

ATidedHumour
  • 183
  • 3
  • 9
  • Have you tried suggestions here: [pandas-read-sql-with-where-clause-using-in](https://stackoverflow.com/questions/53839451/pandas-read-sql-with-where-clause-using-in) – topsail May 06 '23 at 23:58
  • I think you need parentheses around `(:name}` – John Gordon May 07 '23 at 01:38

1 Answers1

0

There is a typo

t = as.text(query)

Should be

t = sa.text(query)

Pablo Henkowski
  • 197
  • 1
  • 6
  • that's just because when I tried to retype the code I made the typo but it's not related to the problem I'm facing, I'll try the suggestions in the comments; – ATidedHumour May 07 '23 at 20:34