title: Using a temporary table to replace a WHERE IN clause
body: <p>I've got the user entering a list of values that I need to query for in a table. The list could be potentially very large, and the length isn't known at compile time. Rather than using <code>WHERE ... IN (...)</code> I was thinking it would be more efficient to use a temporary table and execute a join against it. I read this suggestion in another SO question (can't find it at the moment, but will edit when I do).</p>
  
  <p>The gist is something like:</p>
  
  <pre><code>CREATE TEMP TABLE my_temp_table (name varchar(160) NOT NULL PRIMARY KEY);
  
  INSERT INTO my_temp_table VALUES ('hello');
  INSERT INTO my_temp_table VALUES ('world');
  //... etc
  
  SELECT f.* FROM foo f INNER JOIN my_temp_table t ON f.name = t.name;
  
  DROP TABLE my_temp_table;
  </code></pre>
  
  <p>If I have two of these going at the same time, would I not get an error if Thread 2 tries to create the TEMP table after Thread 1?</p>
  
  <p>Should I randomly generate a name for the TEMP table instead?</p>
  
  <p>Or, if I wrap the whole thing in a transaction, will the naming conflict go away?</p>
  
  <p>This is Postgresql 8.2.</p>
  
  <p>Thanks!</p>