'Postgres OVERLAPS date function in TypeORM

I want to transfer the query to TypeORM.

It looks like this in 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')

I'm writing this query in TypeORM like this:

.where(
  '(equipment_charging.startDate::date, equipment_charging.endDate::date) OVERLAPS (DATE :startDate, DATE :endDate)',
  { startDate, endDate },
)

it gives me error like this:

{"context":"ExceptionsHandler","stack":["QueryFailedError: syntax error at or near \"$1\"\n    at new QueryFailedError 

What am I doing wrong?



Solution 1:[1]

If equipment_charging.startDate and equipment_charging.endDate are already date type in database I think that you could remove ::date

In same idea try to give directly date type for the input.

I also use lot of double quote for query builder in typeorm try this:

.where(
  '("equipment_charging"."startDate", "equipment_charging"."endDate") OVERLAPS (:startDate, :endDate)',
  { startDate, endDate },
)

And convert startDate and endDate to date if needed (with parseIso of date fns for example)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Julien Hovelaque