node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Option to change the result set

Open GJ2511 opened this issue 12 years ago • 4 comments

HI... i m new to postgres . when i m doing client.query("MY QUERY",function(err,rsl{}) the result is coming like rsl.fields as an araay. is there is any way i want result in rsl itself as an array(not wanted field key)

GJ2511 avatar Jun 24 '14 12:06 GJ2511

Hi!

Look into this test. The key is to add rowMode: 'array' to the query config ...

HTH

hoegaarden avatar Jun 24 '14 17:06 hoegaarden

HI... thanks for reply but this is not what i want . Let me give you an example what i want exactly:

var query = client.query("SELECT name FROM users", function(err, result) { console.log(result.rows[0].name); ->gives = TOM

  but instead of this i want my result in
  console.log(result[0].name);   ->gives = TOM

});

GJ2511 avatar Jun 25 '14 04:06 GJ2511

Hi.

I don't think this is possible (I might be wrong though). However, you could for example wrap your result callback(s) to transform the result object ...

hoegaarden avatar Jun 25 '14 06:06 hoegaarden

I figured it out. Thanks for your help.

GJ2511 avatar Jun 25 '14 08:06 GJ2511