You could do something like: order by if ($doc/sort-date castable as xs:date) then xs:date($doc/sort-date) else () empty greatest
As for the indexing part, somebody more knowledgable will have to step in to answer that affirmatively, but I don't think it would hurt to try the following in qconsole if you already have the data and the indexes setup: order by $doc/sort-date empty greatest -Ryan Dew On Jul 12, 2012, at 6:29 AM, Michael Sokolov wrote: > I have a date-valued element range index. I want to use it for > sorting. When I do that using an expression like this: > > order by xs:date($doc//sort-date) > > I get errors when the $doc sequence contains documents that have no > sort-date. > > What is the recommended approach to handling nulls when sorting? Ideally > we would want them to sort last. > > If I just use > > order by $doc//sort-date > > will the index come in to play? > > -Mike Sokolov > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
