Search code examples
pythonpython-2.7odbcteradataexecute

Teradata Python: teradata.api.InterfaceError


I have a simple select query from a python script to select data from Teradata DB shown below,

session.execute("select distinct v_column from a_table where a_column in (?)",(value))

Value in this case is a tuple with values derived from other bunch of queries.

This query works just fine if I pass in the one value from the variable. For anything more than 1 - I had to change my query to contain more place holders like this (?,?).

I wanted to make this dynamic or generic place holder that can work irrespective. I tried few options and does not seem to make sense to me. Any better suggestions ?

Error with single placeholder with more than one value: teradata.api.InterfaceError: ('PARAMS_MISMATCH', 'The number of supplied parameters (2) does not match the expected number of parameters (1).')


Solution

  • Never mind, it worked using the new way of working with place holders "{}".format()

    Working Query:

    session.execute("select distinct v_column from a_table where a_column in{}".format(value))