I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When I try to use BulkCreate with the parameters ignoreDuplicates: false, updateOnDuplicate: [...] to make the inserts accuse this error:
DatabaseError [SequelizeDatabaseError]: syntax error at or near ")"
at Query.formatError (C:\Dev\Node\api-agruppa-suite\node_modules\sequelize\lib\dialects\postgres\query.js:366:16)
at C:\Dev\Node\api-agruppa-suite\node_modules\sequelize\lib\dialects\postgres\query.js:72:18
at tryCatcher (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\promise.js:725:18)
at _drainQueueStep (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Dev\Node\api-agruppa-suite\node_modules\bluebird\js\release\async.js:15:14)
at processImmediate (internal/timers.js:439:21) {
name: 'SequelizeDatabaseError',
parent: error: syntax error at or near ")"
at Parser.parseErrorMessage (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\parser.js:278:15)
at Parser.handlePacket (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\parser.js:39:38)
at Socket. (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\index.js:8:42)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
length: 93,
name: 'error',
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '56140',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1127',
routine: 'scanner_yyerror',
original: error: syntax error at or near ")"
at Parser.parseErrorMessage (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\parser.js:278:15)
at Parser.handlePacket (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\parser.js:39:38)
at Socket. (C:\Dev\Node\api-agruppa-suite\node_modules\pg-protocol\dist\index.js:8:42)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
length: 93,
name: 'error',
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '56140',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1127',
routine: 'scanner_yyerror',
Expected behavior
That make insert making the necessary updates in the records respecting my unique key composed.
Minimal reproduction of the problem with instructions
DB: Postgress
My table
@table({
tableName: 'tb_categorias_omie',
schema: 'public',
timestamps: false,
paranoid: true,
})
export class Categoria extends Model {
@column({
type: DataType.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
})
public id: number;
@foreignkey(() => Empresa)
@column({
allowNull: false,
unique: 'compositeIndex',
type: DataType.INTEGER,
})
public id_empresa: number;
@BelongsTo(() => Empresa)
empresa: Empresa;
@column({ allowNull: false, type: DataType.TEXT })
public descricao: string;
@column({ allowNull: false, type: DataType.TEXT })
public descricao_padrao: string;
@column({ allowNull: false, unique: 'compositeIndex', type: DataType.STRING })
public codigo: string;
@column({ allowNull: false, type: DataType.STRING })
public categoria_superior: string;
@column({ allowNull: false, type: DataType.STRING })
public categoria_inativa: string;
@column({ allowNull: false, type: DataType.STRING })
public categoria_despesa: string;
@column({ allowNull: false, type: DataType.TEXT })
public natureza: string;
}
BulkCreate code:
await Categoria.bulkCreate(categorias, {
returning: true,
validate: true,
ignoreDuplicates: false,
updateOnDuplicate: [
'categoria_superior',
'categoria_inativa',
'categoria_despesa',
'descricao',
'descricao_padrao',
'natureza',
],
});
My dependencies:
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/config": "^0.5.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/platform-socket.io": "^7.3.2",
"@nestjs/schedule": "^0.4.0",
"@nestjs/sequelize": "^0.1.0",
"@nestjs/websockets": "^7.3.2",
"moment": "^2.27.0",
"pg": "^8.3.2",
"pg-hstore": "^2.3.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"sequelize": "^5.22.3",
"sequelize-typescript": "^1.1.0"
},
What is the motivation / use case for changing the behavior?
I do an integration with an accounting system, it has some categories that use the same code for all companies but that can suffer changes in the name, standard name and superior category according to the need of that company.
Environment
Nest version: 7.4.1
For Tooling issues:
- Node version: 12.13.1
- Platform: Windows
Others:
Vscode