title: Pass variable into SQLAlchemy query
body: <p>Trying to pass a variable (a set) into an sqlalchemy query.</p>
  
  <p>Found this: <a href="https://stackoverflow.com/questions/13190392/how-can-i-bind-a-list-to-a-parameter-in-a-custom-query-in-sqlalchemy">How can I bind a list to a parameter in a custom query in sqlalchemy?</a> But it requires you to know many items there are. The number of entries changes at any given moment. </p>
  
  <p>My <a href="https://stackoverflow.com/questions/21336914/search-a-set-in-sqlalchemy-query">previous question</a> went mostly unanswered unfortunately so I figured I'd re-iterate what I'm trying to do here. </p>
  
  <p>Basically, I have this variable: <code>sites = set(db1).intersection(db2)</code> and I'm trying to pass it into this sql alchemy query: </p>
  
  <p><code>'test': DBSession.query(A_School.cis_site_id.in_(sites)).all(),</code></p>
  
  <p>But I get <code>invalid syntax</code> errors and <code>invalid parameter type</code> errors...I can't get this thing to do what I want it to do. DB1 and DB2 are, as you mightve guessed, 2 different databases. </p>
  
  <pre><code>db1 = cis_db.query(site.site_id).join(site_tag).filter(site_tag.tag_id.like(202)).all()
  db2 = DBSession.query(A_School.cis_site_id).all()
  </code></pre>
  
  <p>Full error:</p>
  
  <pre><code>ProgrammingError: (ProgrammingError) ('Invalid parameter type.  param-index=0 param-type=KeyedTuple', 'HY105') u'SELECT [A_School].cis_site_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) AS anon_1 
  FROM [A_School]' ((14639,), (14709,), (14587,), (14966,), (14625,), (14589,), (15144,), (15171,)  ... displaying 10 of 18 total bound parameter sets ...  (15133,), (14036,))
  </code></pre>