title: How to check if value is in a list or if the list is empty?
body: <p>I'm using <a href="http://initd.org/psycopg/" rel="noreferrer"><code>psycopg2</code></a> to access a PostgreSQL database through Python 3, and I'm attempting to make a query where I want to select all users whose name are in a list, <em>if the list is not empty</em>. If the provided list is empty, I want to ignore the condition, i.e. select all users regardless of their name.</p>
  
  <p>I've already tried the following three calls:</p>
  
  <pre><code># Using list
  cursor.execute(
      "SELECT age FROM user WHERE %(names) = '{}' OR user.name IN %(names)s",
      {'names': []},
  )
  
  # Using tuple
  cursor.execute(
      "SELECT age FROM user WHERE %(names) = () OR user.name IN %(names)s",
      {'names': ()},
  )
  
  # Using both list and tuple
  cursor.execute(
      "SELECT age FROM user WHERE %(names_l) = '{}' OR user.name IN %(names_t)s",
      {'names_l': [], 'names_t': ()},
  )
  </code></pre>
  
  <p>But they all raise an invalid syntax error from one point or another:</p>
  
  <pre><code># Using list
  psycopg2.ProgrammingError: syntax error at or near "'{}'"
  LINE 17:         user.name IN '{}'
  
  # Using tuple
  psycopg2.ProgrammingError: syntax error at or near ")"
  LINE 16:         () == ()
  
  # Using both list and tuple
  psycopg2.ProgrammingError: syntax error at or near ")"
  LINE 17:         user.name IN ()
  </code></pre>