title: When using psycopg2 to query my database with Python, how can I correctly reference row values in an ILIKE statement?
body: <p>I have a database that I've successfully accessed using psycopg2, but I'm running into trouble correctly using ILIKE to compare a Python variable to row values from my database. Here's the code:</p>
  <pre><code>for i in range(1, len(fin_df)):
          cursor.execute(&quot;&quot;&quot;WITH res as (SELECT year, symbol, model, make, progressive_symbol FROM \&quot;Motorcycle\&quot;.motorcycles WHERE  %s ILIKE '%' || model || '%'), maxyr AS (SELECT MAX(year) FROM res) SELECT * FROM res WHERE year IN (SELECT * FROM maxyr)&quot;&quot;&quot;, (fin_df.model[i],))
  </code></pre>
  <p>Which returns a tuple index out of range error. To clarify, the model variable is a row from the postgres table. If possible, I'd also like to figure out how to to do the reverse- as in, see where model ILIKE the Python variable.
  Thanks!</p>