【问题标题】:TypeORM: How does TypeORM compare timestamps?TypeORM:TypeORM 如何比较时间戳?
【发布时间】:2021-03-16 03:36:10
【问题描述】:

我正在使用 TypeORM 来运行这个查询:

SELECT "subagreementlog"."created_at" AS "subagreementlog_created_at" FROM "subagreement_logs" "subagreementlog" WHERE "subagreementlog"."subagreement_id" = $1 AND "subagreementlog"."created_at" > $2 LIMIT 1 -- PARAMETERS: ["0d71866e-3b78-4321-8ae8-dc39ffe82dbc","2020-11-12T13:57:16.618Z"]

我正在寻找“created_at”值大于“2020-11-12T13:57:16.618Z”的记录,但这实际上返回的值与我所说的等于或大于相同。

result is: { subagreementlog_created_at: 2020-11-12T13:57:16.618Z }

寻求指导说明为什么会出现这种情况。

另外,这里是实体中所述字段的定义

@CreateDateColumn({ name: "created_at" })
@Field(_ => GraphQLISODateTime, {
  description: "Timestamp the subagreement was changed"
})
public createdAt!: Date;

【问题讨论】:

  • Postgresql 在时间戳中存储微秒。你能在subagreementlog.created_at查看这些吗?

标签: node.js typescript postgresql typeorm


【解决方案1】:

您是否尝试过增加参数值?例如,而不是

2020-11-12T13:57:16.618Z 尝试 2020-11-12T13:57:17.618Z(+1 秒)

我相信即使数据明显在参数之前,您仍然会得到匹配。

如果您找到匹配项,我怀疑您正在将数据存储在一个时区(可能是 UTC)中,但使用本地时间作为参数。我不知道 TypeORM,但它可能会在读写时转换时区,但不会转换参数。

只是一个猜测,但我希望它有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-28
    • 2019-07-30
    • 2012-05-16
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2021-04-25
    相关资源
    最近更新 更多