Karl, Regarding Question #1: Mark Logic is simply following the definition of the dateTime data type in the XSD specification (which is where XML data types are defined) here (http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#dateTime); I can't speak for Mark Logic, but I suspect it would take a pretty strong scenario to evoke departure from strict adherence to the spec for something as fundamental as the built-in data types, if that would ever happen at all. The xdmp:strftime function (http://developer.marklogic.com/pubs/4.1/apidocs/Ext-1.html#xdmp:strftime) lets you go from the strict format to a human-readable one, but I don't know of a one-stop function to go the other direction. However, it should be pretty simple (as long as your internal date formatting is reasonably predictable) to do the conversion using the built-in string functions (http://developer.marklogic.com/pubs/4.1/apidocs/StringBuiltins.html).
Doug Glidden Software Engineer The Boeing Company [email protected] _____ From: [email protected] [mailto:[email protected]] On Behalf Of Karl Erisman Sent: Tuesday, December 15, 2009 14:30 To: General Mark Logic Developer Discussion Subject: [MarkLogic Dev General] dateTime format, range queries,and misbehaving cts:and-queries I am using the cts library to generate "and-queries" that join dateTime range queries. The data I'm searching has dates in the format "YYYY-MM-DD hh:mm:ss" (note the space). I created a dateTime range index AFTER the docs were loaded. When I run a query with search criteria including a dateTime specified using what appears to be the required format for dateTimes, e.g. "2009-12-15T11:52:00", I get an error that seems to result from the invalid date formats in docs already in the DB (i.e. the error complains about documents in the DB, not about the query I'm running). If I try to use the same format, querying using a <date string> with a space instead of a 'T', as in the loaded docs, I get error "invalid cast: <date string> cast as xs:dateTime" -- this time the error is complaining about my query. Not surprising since (I think) the 'T' is required for ML dateTimes. (Question #1: dateTime formats) Is it really necessary that the data for which dateTime range indexes are created in the DB be in the "YYYY-MM-DDThh:mm:ss" format (where the 'T' is literal)? What do others do to get around this restriction? Next, I copied a document from the collection I was using, changed dateTime formats to include the 'T', loaded the document, and re-indexed the database. Now, when I run the query that previously resulted in an error using this modified document as the target, the document is returned as satisfying the query. (Question #2: and-query() problem -- see code below) However, if I run the same query (q1) but join it in a cts:and-query() with any other query that also is satisfied by the document when the query is run by itself (q2), I get no results. So it seems to be a case where cts:and-query() does NOT return the intersection of its constituent queries (as it is defined to do). What might cause that? ==== code... ==== (: q1: RETURNS THE TEST DOCUMENT: :) cts:search(fn:doc("my-test-doc.xml"), cts:and-query(( cts:element-query(fn:QName("http://ns", "L1"), cts:element-query(fn:QName("http://ns", "L2"), cts:element-query(fn:QName("http://ns", "L3"), cts:element-range-query(fn:QName("http://ns", "StartDate"), ">=", xs:dateTime("1900-01-01T00:00:00"))))) )) ) (: q2: RETURNS THE TEST DOCUMENT: :) cts:search(fn:doc("my-test-doc.xml"), cts:and-query(( cts:element-query(fn:QName("http://ns", "L1"), cts:element-query(fn:QName("http://ns", "L2"), cts:element-query(fn:QName("http://ns", "L3"), cts:element-value-query(fn:QName("http://ns", "ID"), "X032923492")))) )) ) (: Q = cts:and-query(q1, q2): RETURNS NO RESULTS: :) cts:search(fn:doc("my-test-doc.xml"), cts:and-query(( cts:element-query(fn:QName("http://ns", "L1"), cts:element-query(fn:QName("http://ns", "L2"), cts:element-query(fn:QName("http://ns", "L3"), cts:element-range-query(fn:QName("http://ns", "StartDate"), ">=", xs:dateTime("1900-01-01T00:00:00"))))), cts:element-query(fn:QName("http://ns", "L1"), cts:element-query(fn:QName("http://ns", "L2"), cts:element-query(fn:QName("http://ns", "L3"), cts:element-value-query(fn:QName("http://ns", "ID"), "X032923492")))) )) ) ==== Thanks, Karl
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
