title: Extracting results from a SELECT * in node pg
body: <p>I have a Postgresql stored function defined as following:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION SessionGet(
      sid            varchar)
      RETURNS "SESSION" AS $$
      SELECT * FROM "SESSION" WHERE "SESSION_ID" = sid;
  $$ LANGUAGE sql;
  </code></pre>
  
  <p>I call it from node using the PG module with:</p>
  
  <pre><code>SELECT SessionGet('SID-1'::varchar);
  </code></pre>
  
  <p>The <code>session</code> table is defined as:</p>
  
  <pre><code>CREATE TABLE "SESSION"
  (
    "SESSION_ID" character varying NOT NULL DEFAULT ''::character varying,
    "SESSION" json NOT NULL DEFAULT '{}'::json,
    "LAST_UPDATE" bigint DEFAULT 0,
    CONSTRAINT "SESSION_PK" PRIMARY KEY ("SESSION_ID")
  )
  WITH (
    OIDS=FALSE
  );
  </code></pre>
  
  <p>I am trying to retrieve the returned result as following:</p>
  
  <pre><code>client.query(sql, function(err, result) {
              done(); // Releasing connection to the pool
              if ( err ) {
                  callback(err);
              } else if ( result.rows.length &gt; 0 ) {
                  var ttmp = result.rows[0];
                  var tmp1 = ttmp[0];
                  console.log("Res[0]: " + tmp1);
                  callback(err,result.rows[0]);
              } else {
                  callback(err);
              }
          });
  </code></pre>
  
  <p>Although <code>result.rows.length</code> is <code>&gt; 0</code>, <code>result.rows[0][0]</code> is undefined. How can I retrieve the field values from the returned row?</p>