0

I am trying to implement a code where i am trying to pass token as parameter For e.g.

Select * 
from user U 
where tokenid=? 
Left outer join User U1 ON U.Id=U1.Id 
Left outer Join Employee E 
where Dept_Id In (
    Select Dept_id 
    from Department 
    where token_id = ?
) ON empoyee.id = user.id

Here i am trying to implement this in dataframe where i am using the code

df=pd.read_sql_query(query,con,params="value")

But i am getting the error that 'The SQL contains 2 parameter markers, but 36 parameters were supplied' Cab you please help me in implementing this code

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • `params` should be a list or tuple with two values, e.g. `params=("value", "value")` – Barmar Aug 31 '22 at 06:33
  • 1
    Your SQL syntax is wrong. You can't have `where` before `left outer join`. – Barmar Aug 31 '22 at 06:33
  • `on employee.id = user.id` should be before `where Dept_Id IN ...` – Barmar Aug 31 '22 at 06:38
  • Thanks , it worked when i passed params="value","value" – user19884738 Sep 01 '22 at 08:26
  • Is there any other way in which i can pass the parameters, because if the same token_id is being used at multiple places then i have to pass the parameters as well multiple times. Is there a way to pass the parameter only one time? – user19884738 Sep 01 '22 at 10:21
  • It depends on the database driver you're using. Some support named parameters, then you can pass a dictionary, and it should be possible to reuse the same name multiple times. See https://stackoverflow.com/questions/24408557/pandas-read-sql-with-parameters – Barmar Sep 01 '22 at 14:53

0 Answers0