title: How to set schema with node-postgres
body: <p>I'm trying to query against a schema called <code>DOCUMENT</code> in my postgres db using <a href="https://www.npmjs.com/package/pg" rel="noreferrer">node-postgres</a>.</p>
  
  <p>I can't seem to get a query to run against the specified schema.</p>
  
  <p>This query runs fine directly against postgres using psql</p>
  
  <pre><code>SELECT * FROM "DOCUMENT".document_metadata m 
  LEFT OUTER JOIN "DOCUMENT".document_attributes a 
  ON a.document_id = m.id
  </code></pre>
  
  <p>This code produces the error below</p>
  
  <pre class="lang-js prettyprint-override"><code>const query = `SELECT * FROM "DOCUMENT".document_metadata m 
                 LEFT OUTER JOIN "DOCUMENT".document_attributes a 
                 ON a.document_id = m.id`
  const metadata = await db.query(query)
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>error: relation "DOCUMENT.document_metadata" does not exist
      at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:602:11)
      at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:399:19)
      at Socket.&lt;anonymous&gt; (/usr/src/app/node_modules/pg/lib/connection.js:121:22)
      at Socket.emit (events.js:189:13)
      at addChunk (_stream_readable.js:284:12)
      at readableAddChunk (_stream_readable.js:265:11)
      at Socket.Readable.push (_stream_readable.js:220:10)
      at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  </code></pre>
  
  <p>I've also tried this</p>
  
  <pre class="lang-js prettyprint-override"><code>const query = `SET search_path TO 'DOCUMENT';
                 SELECT * FROM document_metadata m 
                 LEFT OUTER JOIN document_attributes a 
                 ON a.document_id = m.id;`
  
  const metadata = await db.query(query)
  </code></pre>
  
  <p>which produces the error</p>
  
  <pre><code>error: relation "document_metadata" does not exist
      at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:602:11)
      at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:399:19)
      at Socket.&lt;anonymous&gt; (/usr/src/app/node_modules/pg/lib/connection.js:121:22)
      at Socket.emit (events.js:189:13)
      at addChunk (_stream_readable.js:284:12)
      at readableAddChunk (_stream_readable.js:265:11)
      at Socket.Readable.push (_stream_readable.js:220:10)
      at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  
  </code></pre>
  
  <p><strong>Update</strong>
  When I run these same queries directly in psql I see like 10 rows with table names. When I run this through my node code I see no rows:</p>
  
  <pre class="lang-js prettyprint-override"><code>const metadata4 = await db.query('SHOW search_path;')
  console.log('search_path after setting = ', metadata4.rows) // prints [ { search_path: '"DOCUMENT"' } ]
  
  const tables = await db.query(`SELECT * FROM information_schema.tables where table_schema = 'DOCUMENT';`)
  console.log('tables = ', tables.rows) // prints []
  </code></pre>