Error comparing DateTime

#1

Hi all, I am using function compareTo in fetch clause on a type that I have created. The syntax is this:

Threshold.fetch({ filter: ‘compareTo(startDate, “2018-01-01”) == -1’});

Type is:

/**
The Threshold c3type is be created to store different thresholds
related to Facility
**/
entity type Threshold schema name “THRESHOLD” {

facility : Facility

alertType : string

startDate : datetime

endDate : datetime

threshold : ExactDimension

}

But I have this error:

“Unable to execute sql SELECT T.FACILITY_R, T.ALERTTYPE_S, T.STARTDATE_T, T.STARTDATE_I, T.ENDDATE_T, T.ENDDATE_I, T.THRESHOLD_VALUE_D, T.THRESHOLD_UNIT_R, T.ID, T.VERSION, T.NAME, T.TENANT_TAG_ID, T.CREATED, T.CREATED_I, T.CREATED_BY, T.UPDATED, T.UPDATED_I, T.UPDATED_BY, T.META_TIMESTAMP_T, T.META_TIMESTAMP_I, T.META_COMMENT, T.PROVENANCE, T.SOURCE
FROM C3_2_THRESHOLD T
WHERE T.TENANT_TAG_ID=:v1 AND (T.ID=:v2 AND case when T.STARTDATE_T = :v3 then 0 else case when T.STARTDATE_T > :v4 then 1 else -1 end end= -:v5)
ORDER BY T.ID
LIMIT 2001
ERROR: operator does not exist: timestamp without time zone = character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 419”

Where is my mistake? Thank you

#2

I would just use the expression engine function dateTime: Threshold.fetch({ filter: ‘startDate < dateTime(“2018-01-01”)’});

You might be able to also do Threshold.fetch({ filter: ‘compareTo(startDate, dateTime(“2018-01-01”)) == -1’});

#3

Thank you, it works !