I'm trying to make a timestamp comparison after parsing a couple strings that have the default "dow mon dd hh:mm:ss zzz yyyy" in java, using MyBatisPlus for a postgresql DB.
I'm updating legacy code so I'm not able to change a lot of the structure, so that's a constraint since it's using QueryWrapper to execute all queries. I've tried to read the documentation, but I mostly find references in chinese language which don't get translated properly.
What I have tried so far is the following:
QueryWrapper<SomeClassWithBaseMapper> result = new QueryWrapper();
result.eq("firstcolumn", firstValueToCheck);
if(dateStrFilter != null) {
try{
//PostgreSQL Syntax
String dateConversionEq = "(TO_TIMESTAMP(SUBSTRING(" + START_TIMESTAMP +
",5), 'Mon DD HH24:MI:SS xxx YYYY')+(INTERVAL'10 MINUTES')) >= (TO_TIMESTAMP(SUBSTRING({0},5), " +
"'Mon DD HH24:MI:SS xxx YYYY'))";
result.apply(dateConversionEq, dateStrFilter);
} catch(Exception e){
System.out.println(e);
}
}
I use substring to remove the starting name of the day (since I don't see any matching format pattern in postgresql docs).
I attempt to use +(INTERVAL'10 MINUTES') basically to check whether the given date is at most 10 minutes old. But I get this error:
expected "[, ::, *, /, %, +, -, ||, ~, !~, NOT, LIKE, ILIKE, REGEXP, IS, IN, BETWEEN, AND, OR, YEAR, MONTH, DAY, HOUR, MINUTE, SECOND"
If I remove this inline interval addition, the query works, but obviously I need results that are recent (in the last 10 minutes). Any suggestion to make this work?
Thanks!