首页 > 解决方案 > Sequelize 返回错误的结果

问题描述

我将 sequelize 与 Postgresql 一起使用,如果我在 pgadmin postgresql 客户端中运行以下查询,我有正确的值:

select students->>'name', students->>'birthday', u.created_at
from users u, json_array_elements(u.information->'Section B') students 
where u.created_at::date = '2019-08-01T00:00:00.000Z'

我的学生表是这样的:

id - serial2
students - json
created_at: timestamp with time zone

当我在 sequelize 中运行与以下相同的查询时,结果为空:

sequelize.query(`select students->>'name', students->>'birthday', u.created_at
from users u, json_array_elements(u.information->'Section B') students 
where u.created_at::date = :created_at'`, {
            type: sequelize.QueryTypes.SELECT,
            replacements: {created_at: where_date }

where_date = 2019-08-01T00:00:00.000Z

在我的模型定义中,我timestamps: true已经尝试使用timestamps: false相同的空结果。

标签: node.jspostgresqlsequelize.js

解决方案


就我而言,只是数据库配置不匹配,所以我在 pgadmin 中查询一个数据库并指向应用程序中的另一个数据库。很明显,但仍然值得一看凭据。


推荐阅读