title: How to get postgresql to interpret column names from sub-select?
body: <p>I have the following query in PostgreSQL 9.4.1 on x86_64-apple-darwin14.1.0, compiled by Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn), 64-bit.</p>
  
  <pre><code>SELECT ( 
      SELECT string_agg(trim(cols::text, '()'), ', ') 
      FROM (
          SELECT 'dog.' || column_name 
          FROM information_schema.columns 
          WHERE table_name='dog') 
          AS cols
          ) 
  FROM dog;
  </code></pre>
  
  <p>This produces the following output once for every row in the dogs table:</p>
  
  <pre><code>dog.id, dog.created_date, dog.updated_date, dog.author_id, dog.mother_id, dog.start_date, dog.end_date, dog.session_type_id, dog.note, dog.cancelled, dog.life_phase
  </code></pre>
  
  <p>But the problem is that the outer select query has not dereferenced the column names and interpreted them as column names but rather labeled the column string_agg and spit out the column names once for every row in the dog table.</p>
  
  <p>How do I get postgresql to ensure that the inner select generating the column names is interpreted by the outer select properly?</p>