title: Postgresql: Set variable equal to a specific entry in an array
body: <p>I have a table <code>newb</code> that looks something like this:</p>
  
  <pre><code>tablename | columnname
  -----------------------
  walls     |  id
  floors    |  rowid
  </code></pre>
  
  <p>First I create an array:</p>
  
  <pre><code>CREATE TABLE finalsb
  (
      tabnam newb ARRAY
  );
  </code></pre>
  
  <p>Then I put data from a table into the array:</p>
  
  <pre><code>INSERT INTO finalsb VALUES(ARRAY(SELECT newb FROM newb));
  </code></pre>
  
  <p>The following statement displays <code>'id'</code> from table newb:</p>
  
  <pre><code>SELECT tabnam[1].columnname FROM finalsb;
  </code></pre>
  
  <p>I want to do something like:</p>
  
  <pre><code>Declare colvar varchar,tabvar varchar
  colvar = Select tabnam[1].columnname from finalsb;
  tabvar = Select tabnam[1].tablename from finalsb;
  </code></pre>
  
  <p>My main goal is to use:</p>
  
  <pre><code>SELECT * FROM tabvar WHERE colvar = "somevalue";
  </code></pre>
  
  <p>Can anyone tell me how I can declare the <code>SELECT</code> statement as a variable?</p>