首页 > 解决方案 > Marklogic SQL93 和日期比较

问题描述

Marklogic 内置了 SQL92 标准,MakLogic 中的文档有一些关于日期函数的详细信息

我有一个简单的查询来将日期与传入的字符串日期进行比较。但似乎没有办法将字符串转换为与 SQL92 的 MarkLogic 实现内联的日期。

我查看了标准函数,它们有一个 curdate,但不等同于 CAST 或 CONVERT,curdate 也不会带参数。

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

在这种情况下,我想返回 2019 年 11 月 1 日之后的所有日期

标签: sqldatemarklogic

解决方案


需要使用绑定。感谢网站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();

推荐阅读