【发布时间】:2020-01-10 01:26:58
【问题描述】:
Offer.findAll({
where: {
userId: id
},
attributes: [
"productDetailId",
"id",
"createdAt",
"userId",
[Sequelize.fn("MAX", Sequelize.col("offerPrice")), "offerPrice"]
],
group: ["productDetailId"],
include: [
{
model: ProductDetail
}
]
})
我有上面的sequelize 查询,它旨在为每个ProductDetail 找到最大offerPrice 的offer,并将结果按productDetailId 分组。以上在mysql 中有效,但在postgres 中引发错误。我怀疑这是因为select 语句包含不在group by 中的字段,这是postgres 不允许的,但我不确定如何更新它。
更新:
错误信息:
error": {
"name": "SequelizeDatabaseError",
"parent": {
"name": "error",
"length": 169,
"severity": "ERROR",
"code": "42803",
"position": "43",
"file": "parse_agg.c",
"line": "1388",
"routine": "check_ungrouped_columns_walker",
【问题讨论】:
-
您能否分享您收到的执行此查询的错误?
标签: sql database postgresql group-by sequelize.js