Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled rejection error on knex.batchInsert with postgres #1880

Closed
jehy opened this issue Jan 26, 2017 · 4 comments
Closed

Unhandled rejection error on knex.batchInsert with postgres #1880

jehy opened this issue Jan 26, 2017 · 4 comments

Comments

@jehy
Copy link

@jehy jehy commented Jan 26, 2017

Doing

 knex.batchInsert('keys', rows, rows.length);

when having duplicate key causes unhandled rejection error - can not catch it as a promise or with try\catch:

Unhandled rejection error: insert into "keys" ("count", "created_at", "is_active", "key", "rsa_key_id", "updated_at") values ($1, $2, $3, $4, $5, $6), ($7, $8, $9, $10, $11, $12), ($13, $14, $15, $16, $17, $18), ($19, $20, $21, $22, $23, $24), ($25, $26, $27, $28, $29, $30), ($31, $32, $33, $34, $35, $36), ($37, $38, $39, $40, $41, $42), ($43, $44, $45, $46, $47, $48), ($49, $50, $51, $52, $53, $54), ($55, $56, $57, $58, $59, $60) - duplicate key value violates unique constraint "keys_rsa_key_id_unique"
at Connection.parseE (.../node_modules/pg/lib/connection.js:554:11)
at Connection.parseMessage (.../node_modules/pg/lib/connection.js:381:17)
at Socket. (.../node_modules/pg/lib/connection.js:117:22)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:534:20)

Steps to reproduce - try catching error when inserting bulk values with duplicated keys:

knex.schema.createTable('test', function (table) {
      table.string('col');
      table.unique('col');
    }).then(function () {
      var rows = [{'col': 'a'}, {'col': "a"}];
      return knex.batchInsert('test', rows, rows.length);
    }).catch(function () {
      console.log('not coming here');
    });

knex 0.12.6
pg 6.1.2
node 5.12.0

@lhaggar
Copy link

@lhaggar lhaggar commented Feb 1, 2017

Having this same issue but with Oracle.

knex 0.12.6
oracle db 11
node 6.9.3

Loading

@daniel78uk
Copy link

@daniel78uk daniel78uk commented Feb 1, 2017

I'm seeing the same issue!

knex 0.12.6
oracle db 11 xe
node 6.9.4

Loading

@getvega
Copy link

@getvega getvega commented Mar 22, 2017

Same issue here - knex 0.12.6

Loading

@wubzz
Copy link
Member

@wubzz wubzz commented Mar 22, 2017

#1984

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants