【问题标题】:How to handle timestamp with timezone on postgres with knex.js如何使用 knex.js 在 postgres 上处理带有时区的时间戳
【发布时间】:2016-05-25 15:57:32
【问题描述】:

我正在尝试将以下 sql 查询翻译成 knex:

select count(*) as finished_on_time from task_history 
where  date = 20160303 
       and store_id = 2 
       and (schedule_start_time at time zone 'Australia/sydney' + interval '1' minute * floor (group_duration) )::time >= (finish_time at time zone 'Australia/sydney')::time
  • 日期字段的格式为 yyyymmdd

这是我一直在尝试的 knex:

db.table('task_history')
.count('*')
.where({date: request.params.storeid, store_id: request.params.storeid }) 
??????

如您所料,我不确定使用哪个子句来处理 sql 语法 [at time zone Australia/sydney]。

我一直试图在互联网上找到任何类似的解决方案,但最终到了这里。

【问题讨论】:

    标签: postgresql knex.js


    【解决方案1】:

    http://knexjs.org/#Builder-whereRaw

    db.table('task_history')
        .count('*')
        .where({date: request.params.storeid, store_id: request.params.storeid })
        .whereRaw("(schedule_start_time at time zone 'Australia/sydney' + interval '1' minute * floor (group_duration) )::time >= (finish_time at time zone 'Australia/sydney')::time")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-08
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2015-11-09
      相关资源
      最近更新 更多