Search code examples
node.jspostgresqlpg-promise

Is it possible to get `INSERT oid count` data after INSERT command with pg-promise?


When I use psql, there is confirmation after INSERT command. For example:

t34=# INSERT INTO t VALUES ('test');
INSERT 0 1

Is it possible to get this data (0, 1) with pg-promise package?

P.S. I speak about output INSERT oid count


Solution

  • db.one('INSERT INTO t VALUES($1) RETURNING *', 'test')
        .then(data => {
            /* data = the inserted row object */
        })
        .catch(error => {
            /* failed */
        });
    

    See method one.

    Relevant reads: Multi-row insert with pg-promise.