Note that there are some explanatory texts on larger screens.

plurals
  1. POdoes node-postgres support multiple resultsets
    text
    copied!<p>I have a PostgresQL function that returns multiple resultsets. I can extract these resultsets in .net without a problem (so I know my function works correctly), but I am having trouble doing so with node-postgres.</p> <p>The result object returns an array of 7 items which matches the number of datasets returned. </p> <p>In Node, the each of the 7 rows simply contains a string of <code>&lt;unnamed portal 1&gt;</code>.</p> <pre><code>connection.query("BEGIN"); connection.query({text: "SELECT getoperationaldatasetmodel($1)", values : [clientid]}, function(err, results) { if (err) { connection.query("COMMIT"); self.pool.release(connection); callback(err); } else { var opsDataset = null; var rows = results.rows; // this returns 7 rows but the rows do not contain data but rather the name of the dataset. } </code></pre> <p>So: does node-postgres support multiple result sets and if yes, any suggestions on how to extract?</p> <p>EDIT: Here is the code I used with node-postgres should someone else need to use it in the future.</p> <pre><code>// must wrap in a transaction otherwise won't be able to see the multiple sets. connection.query("BEGIN"); connection.query({text: "SELECT myfunction($1)", values : [clientid]}, function(err, results) { if (err) { // handle error here connection.query("COMMIT;"); } else { connection.query('FETCH ALL FROM "&lt;unnamed portal 1&gt;"', function(err, r1) { // r1.rows will contain the data for the first refcursor }); connection.query('FETCH ALL FROM "&lt;unnamed portal 2&gt;"', function(err, r2) { // r2.rows will contain the data for the second refcursor }); // remember to handle the closure of the transaction }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload