title: sqlalchemy.exc.OperationalError: stack depth limit exceeded
body: <p>I'm getting a <code>sqlalchemy.exc.OperationalError</code> error when I perform the following query:</p>
  
  <pre><code>    present_keys = self.engine.execute(
          _sql.select(
              [self.table.columns.qid, self.table.columns.did],
              _sql.tuple_(self.table.columns.qid, self.table.columns.did).in_(
                  [(row['qid'], row['did']) for row in rows]
              )
          )
      ).fetchall()
  </code></pre>
  
  <p>The thing is, the query works for small amounts of rows like ~5k, but when I try to run it with around 50~100k I get this error.</p>
  
  <p>I guess the query itself is a really bad way to do what I want. (I'm just checking which rows are already in the database, so I can separate the ones I need to insert from the ones I need to update).</p>
  
  <p>What is my best option to solve this? Make a different query? Increase some kind of setting inside PostgreSQL/psycopg2?</p>