【发布时间】:2019-08-03 09:44:18
【问题描述】:
我正在使用带有 pg 的 knex 从我的数据库中获取一些数据。 我试图通过 knex 构建的查询是:
select "fixtime" from "positions" order by "fixtime" desc limit(1)
union
select "fixtime" from "positions" order by "fixtime" limit (1)
但是,当我使用“union”时,knex 返回以下查询。当我试图得到结果时,我得到了错误。
console.log(db.select('fixtime').from('positions').orderBy('fixtime').limit(1).union([db.select('fixtime').from('positions').orderBy('fixtime','desc').limit(1)]).toSQL())
这是控制台的结果:
select "fixtime" from "positions"
union
select "fixtime" from "positions" order by "fixtime" desc limit ? order by "fixtime" asc limit ?
db.select('fixtime').from('positions').orderBy('fixtime').limit(1).union([db.select('fixtime').from('positions').orderBy('fixtime','desc').limit(1)]).then(arr => console.log)
这是我得到的错误: 未处理的拒绝错误:“订单”处或附近的语法错误
当我使用单个查询时,我可以获得结果。 如何使用 knex 修复此查询或者它是一个错误?
【问题讨论】: