I got a database with multiple projects which follows a similar structure to the following:
- Schemas for our client Bob: bob_legal, bob_docs, bob_misc
- Schemas for our client Jess: jess_legal, jess_docs, jess_misc
I am currently using f-strings to build the query:
query = f"SELECT * FROM {client}_legal.my_table WHERE country = '{country_name}';"
result = pd.read_sql(query, con)
But I want to parameterise building the query. I tried using the params parameter in panda's read_sql function. But it doesn't work as it outputs the table like this:
SELECT * FROM 'bob'_legal.my_table WHERE country = 'canada';"
The table bob now is wrapped in single quotes and it creates a SQL syntax error. Is there a different way to do achieve the job but still using the read_sql function? There does not seem to be an option for parameterising tables.