title: SQL column names and comparing them to row records in another table in PostgreSQL
body: <p>I have one of those cases where each SQL query works great, but not when I paste them together.</p>
  
  <p>I have two tables.  One is dynamic that allows NULL values.  The other helps fill the null values by providing a user with a questions.  I take the column names from the dynamic table and see if I can get them to match with fields in the other questions table.  Currently, we have this working PHP, but I have been trying put it all into our PostgreSQL database.  </p>
  
  <p>This gets all of the column names from the dynamic table and return a comma separated list of strings.</p>
  
  <pre><code>select array_to_string(array_agg(quote_literal(column_name::text)),',') from
  information_schema.columns where table_name='dynamic_table';
  </code></pre>
  
  <p>It works great, and returns something like: 'notificationemail','birthdate','lastnotificationcheck','createmethod'</p>
  
  <p>If I paste this list directly into my next query, it works and returns rows:</p>
  
  <pre><code>select * FROM questions_table WHERE questioncolumn IN   
  ('notificationemail','birthdate','lastnotificationcheck','createmethod');
  </code></pre>
  
  <p>Now once I paste them together, I get something that runs but returns no rows:</p>
  
  <pre><code>select * FROM questions_table WHERE questioncolumn IN   
  (select array_to_string(array_agg(quote_literal(column_name::text)),',') from
  information_schema.columns where table_name='dynamic_table');
  </code></pre>
  
  <p>I am trying to determine how the static text field is different from the embedded SELECT inside the IN statement.  It seems to make sense that it would work, but obviously, something is different from the dynamic list and the static text.</p>
  
  <p>EDIT:
  Thank you!  I guess I was over thinking things.  By not making it a string list and keeping it an object, it worked right away.</p>