我想将查询转移到TypeORM。
在Postgres看起来是这样的
SELECT *
from equipment_charging
where (equipment_charging."start_date"::date, equipment_charging."end_date"::date) OVERLAPS (DATE '2020-09-10', DATE '2020-09-14')我用TypeORM编写了这样的查询:
.where(
'(equipment_charging.startDate::date, equipment_charging.endDate::date) OVERLAPS (DATE :startDate, DATE :endDate)',
{ startDate, endDate },
)它给了我这样的错误:
{"context":"ExceptionsHandler","stack":["QueryFailedError: syntax error at or near \"$1\"\n at new QueryFailedError 我做错了什么?
发布于 2022-05-10 09:13:28
如果equipment_charging.startDate和equipment_charging.endDate已经是数据库中的日期类型,我认为可以删除::date
同样的想法,尝试为输入直接提供日期类型。
我还在typeorm中对查询生成器使用了很多双引号,请尝试如下:
.where(
'("equipment_charging"."startDate", "equipment_charging"."endDate") OVERLAPS (:startDate, :endDate)',
{ startDate, endDate },
)并在需要时将startDate和endDate转换为日期(例如,使用日期的parseIso )
https://stackoverflow.com/questions/69972557
复制相似问题