question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for INSERT ... RETURNING

See original GitHub issue

Supprt for INSERT … RETURNING could improve existing API. (http://www.postgresql.org/docs/8.4/static/sql-insert.html) Maybe passing argument to Query end event callback will be good approach?

query.on('end', function(row) {
   if(row) {
      // RETURNING uesd
   }
   else {
     // standard end event
   }
});

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
choweycommented, Mar 29, 2012

RETURNING works. It triggers a “row” event just fine.

If you want to use event listeners, then do this:

query.on('row', function (row) {
  // do some stuff
})

Currently the result does not automatically accumulate rows unless you use a callback. If you want to accumulate rows using event listeners, you have to do this:

query.on('row', function (row, result) {
  result.addRow(row);
});
query.on('end', function (result) {
  if (result.rowCount > 0) {
    // RETURNING used
    doSomething(result.rows[0]);
  } else {
    // standard end event
  }
});

This issue could be closed.

0reactions
brianccommented, Mar 30, 2012

Thank you! ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

INSERT...RETURNING - MariaDB Knowledge Base
This returns the listed columns for all the rows that are inserted, or alternatively, the specified SELECT expression.
Read more >
6.4. Returning Data from Modified Rows - PostgreSQL
The INSERT , UPDATE , and DELETE commands all have an optional RETURNING clause that supports this. Use of RETURNING avoids performing an...
Read more >
INSERT .. RETURNING - jOOQ
The Postgres database has native support for an INSERT .. RETURNING clause. This is a very powerful concept that is emulated for all...
Read more >
Support insert returning · Issue #47 · MagicStack/asyncpg
In PostgreSQL INSERT support RETURNING values, but asyncpg on con.exec returns only success result of inserting, how to support returning ...
Read more >
RETURNING clause in INSERT INTO ... SELECT ... possible?
Looks like a the RETURNING clause cannot be used for INSERT INTO SELECT. I tried and it gives error. My DB is 11g...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found