Postgres SequelizeDatabaseError:返回或接近返回的语法错误

Posted

技术标签:

【中文标题】Postgres SequelizeDatabaseError:返回或接近返回的语法错误【英文标题】:Postgres SequelizeDatabaseError: syntax error at or near RETURNING 【发布时间】:2017-02-08 03:08:58 【问题描述】:

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

对象:

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 *;' 

【问题讨论】:

@KevalGohil,不是,这个问题是指 sql2o (java)。 Sequelize 适用于 nodejs 【参考方案1】:

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

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);
                );

【讨论】:

以上是关于Postgres SequelizeDatabaseError:返回或接近返回的语法错误的主要内容,如果未能解决你的问题,请参考以下文章

postgres数据库入门, python 操作postgres

Postgres:将自定义类型从 Java 传递给 postgres 函数

无法创建用户 postgres:角色“postgres”不存在

致命:连接到 postgres 时用户“postgres”的密码验证失败

使用 node-postgres 在 postgres 中存储文件

Postgres.app 无法启动