Pg-promise: helpers.insert property 'xxxxxx' doesn't exist

Created on 28 Nov 2017  路  2Comments  路  Source: vitaly-t/pg-promise

I'm trying to write a reusable query using the insert helper provided.

data = req.body.systemTypes.map(type => ({
        type: type, 
        submissionid: 123123123
    }));

db.any(pgp.helpers.insert(data, ['systemtype_id', 'submission_id'], 'systems_systemtype_submissions') + 'RETURNING id')
    .then(id => {
        console.log("ID: ", id);
    });
    return;

always results in an error :

Error: Property 'systemtype_id' doesn't exist.
at query.replace.name

but if I do a single data insert as such:

db.any(pgp.helpers.insert({systemtype_id: 5, submission_id: 37}, null, 'systems_systemtype_submissions') + 'RETURNING id')
.then(id => {
        console.log("ID: ", id);
    });
    return;

then I get results:

ID: [ anonymous { id: 118 } ]

What I'd like to accomplish is using multidata Inserts as shown here: helpers.insert
specifically this example

const dataMulti = [{val: 123, msg: 'hello'}, {val: 456, msg: 'world!'}];

// Column details are required for a multi-row `INSERT`:

pgp.helpers.insert(dataMulti, ['val', 'msg'], 'my-table');
//=> INSERT INTO "my-table"("val","msg") VALUES(123,'hello'),(456,'world!')

but no matter how I try to format the helpers.insert function (using helpers.Column, helpers.ColumnSet, helpers.values() and as.format() ) the same issue keeps popping up.

Error: Property 'systemtype_id' doesn't exist.
at query.replace.name

I assume I'm just using this incorrectly, I've googled and read your documentation(fantastic by the way) up and down, but I must be missing something.

Any suggestions?

question

All 2 comments

You are passing in data:

data = req.body.systemTypes.map(type => ({
        type: type, 
        submissionid: 123123123
    }));

which doesn't have any systemtype_id, hence the error.

Wow. such a silly mistake. banging my head on this for a while.... should've taken a break.

Thanks for the quick response.

Love the library!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cortopy picture cortopy  路  5Comments

hawkeye64 picture hawkeye64  路  4Comments

alpertuna picture alpertuna  路  4Comments

blendsdk picture blendsdk  路  3Comments

normanfeltz picture normanfeltz  路  4Comments