I have a Postgresql stored function defined as following:
CREATE OR REPLACE FUNCTION SessionGet(
sid varchar)
RETURNS "SESSION" AS $$
SELECT * FROM "SESSION" WHERE "SESSION_ID" = sid;
$$ LANGUAGE sql;
I call it from node using the PG module with:
SELECT SessionGet('SID-1'::varchar);
The session
table is defined as:
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
);
I am trying to retrieve the returned result as following:
client.query(sql, function(err, result) {
done(); // Releasing connection to the pool
if ( err ) {
callback(err);
} else if ( result.rows.length > 0 ) {
var ttmp = result.rows[0];
var tmp1 = ttmp[0];
console.log("Res[0]: " + tmp1);
callback(err,result.rows[0]);
} else {
callback(err);
}
});
Although result.rows.length
is > 0
, result.rows[0][0]
is undefined. How can I retrieve the field values from the returned row?