Postgres SequelizeDatabaseError:RETURNING或其附近的语法错误

时间:2017-02-08 03:08:59

标签: node.js postgresql sequelize.js amazon-redshift

由于某些原因,Sequelize驱动程序正在添加: RETURNING * 到select语句的末尾。有谁知道为什么?

对象:

Lol.create({
                    id: record.dynamodb.NewImage.id.S,
                    userId: record.dynamodb.NewImage.userId.S,
                    summonerId: record.dynamodb.NewImage.summonerId.N,
                    name: record.dynamodb.NewImage.name.S,
                    profileIconId: record.dynamodb.NewImage.profileIconId.N,
                    summonerLevel: record.dynamodb.NewImage.summonerLevel.N,
                    revisionDate: record.dynamodb.NewImage.revisionDate.N,
                    createdAt: record.dynamodb.NewImage.createdAt.S,
                    updatedAt: record.dynamodb.NewImage.updatedAt.S
                }).then(function (user) {
                    console.log(user);
                }).catch(function (err) {
                    console.log(err);
                });

错误:

name: 'SequelizeDatabaseError',
  message: 'syntax error at or near "RETURNING"',
  parent: 
   { [error: syntax error at or near "RETURNING"]
     name: 'error',
     length: 136,
     severity: 'ERROR',
     code: '42601',
     detail: undefined,
     hint: undefined,
     position: '330',
     internalPosition: undefined,
     internalQuery: undefined,
     where: undefined,
     schema: undefined,
     table: undefined,
     column: undefined,
     dataType: undefined,
     constraint: undefined,
     file: '/home/ec2-user/padb/src/pg/src/backend/parser/parser_scan.l',
     line: '699',
     routine: 'yyerror',
     sql: 'INSERT INTO "Lol" ("id","userId","summonerId","name","profileIconId","summonerLevel","revisionDate","createdAt","updatedAt") VALUES (\'463d118c-2139-4679-8cdb-d07249bd2498\',\'a845a2ca-14c9-46de-93c6-d3dd1bd1a8a0\',\'2122373\',\'mariaraujo\',\'716\',\'30\',\'14804545500\',\'2017-01-09 18:50:15.282 +00:00\',\'2017-02-08 00:53:44.853 +00:00\') RETURNING *;' }

1 个答案:

答案 0 :(得分:1)

我可以让它工作,设置返回false:

Lol.create({
                    id: record.dynamodb.NewImage.id.S,
                    userId: record.dynamodb.NewImage.userId.S,
                    summonerId: record.dynamodb.NewImage.summonerId.N,
                    name: record.dynamodb.NewImage.name.S,
                    profileIconId: record.dynamodb.NewImage.profileIconId.N,
                    summonerLevel: record.dynamodb.NewImage.summonerLevel.N,
                    revisionDate: record.dynamodb.NewImage.revisionDate.N,
                    createdAt: record.dynamodb.NewImage.createdAt.S,
                    updatedAt: record.dynamodb.NewImage.updatedAt.S
                }, {returning: false}).then(function (user) {
                    console.log(user);
                }).catch(function (err) {
                    console.log(err);
                });