Lee Arnould
Lee Arnould

Reputation: 123

Marklogic SQL93 and date comparisons

Marklogic has SQL92 standard built in and the documentation in MakLogic has some details on Date Function

I have a simple query to compare a date to a string date passed in. But there seems no way to convert a string to a date inline with MarkLogic implementation of SQL92.

I have looked at the standard function and they have a curdate but no equivalent to CAST or CONVERT nor will curdate take an argument.

select dateStart from namespace.dateTable
where coalesce(dateStart,curdate())> XXX('1 Nov 2019')

I want to return all dates after 1st of Nov 2019 in this case

Upvotes: 1

Views: 110

Answers (1)

Lee Arnould
Lee Arnould

Reputation: 123

Need to utilise Binding. Thanks to the web site Avalon.

const minYear = xs.date('2019-11-01');

//create a binding with the date being passed as a date
var bindings = {"date": minYear};

//add to the SQL the variable @date
var sqlString = `select * from namespace.table 
where dateStart >= @date limit 100
`;

//execute the sql with third argument the binding
xdmp.sql(sqlString, null, bindings).toArray();

Upvotes: 1

Related Questions