sortby (INOXIE8309, Duplicate in sort key)

Hello!

I could not make a properly query to sort data in my tamino db. I have tried in the following ways:

1)
DOC/OPERATION[DATE between “2002-06-01”, “2002-06-10”] sortby(DATE)

2)
DOC[OPERATION/DATE between “2002-06-01”, “2002-06-10”] sortby(DATE)

I also tried:

3)
DOC[OPERATION/DATE between “2002-06-01”, “2002-06-10”] sortby(OPERATION/DATE)

Unfortunately, I got error message:
INOXIE8309, Duplicate in sort key (ino:messageline also includes: Within document with ino:id = 2 there is a sort key which consist of more than a single value)

Documentation also says:

------------
INOXIE8376

Duplicate in sort key

Explanation
The system cannot handle sort key values which consist of more than a single node.

Action
Please try to fix your data or your query.
------------

So, why should I make my query to sort my data by date value?

In advance, thanks.

best regards,
Dariusz Baumann

PS.
On tag “OPERATION/DATE” I make index “standard” in Tamino Schema Editor.

Hello Dariusz,

could you please post the schema that you are having trouble querying?

Could you please also post the 4-digit Tamino version that you are using?
(For example: 4.1.1.9)

Thanks,
Trevor.

Tamino version: 4.1.1.3

Schema:
----------------------
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:tsd = “http://namespaces.softwareag.com/tamino/TaminoSchemaDefinition” xmlns:xs = “http://www.w3.org/2001/XMLSchema”>
xs:annotation
xs:appinfo
<tsd:schemaInfo name = “TEST”>
<tsd:collection name = “COL”></tsd:collection>
<tsd:doctype name = “DOC”>
tsd:logical
tsd:contentclosed</tsd:content>
</tsd:logical>
</tsd:doctype>
tsd:adminInfo
tsd:created2003-05-06T13:49:14.426+01:00</tsd:created>
tsd:modified2003-05-06T13:49:14.426+01:00</tsd:modified>
tsd:versionTSD4</tsd:version>
tsd:server4.1.1.1</tsd:server>
</tsd:adminInfo>
</tsd:schemaInfo>
</xs:appinfo>
</xs:annotation>
<xs:element name = “OPERATION”>
xs:complexType
xs:sequence
<xs:element name = “DATE” type = “xs:date”>
xs:annotation
xs:appinfo
tsd:elementInfo
tsd:physical
tsd:native
tsd:index
tsd:standard</tsd:standard>
</tsd:index>
</tsd:native>
</tsd:physical>
</tsd:elementInfo>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name = “DOC”>
xs:complexType
xs:sequence
<xs:element ref = “OPERATION” maxOccurs = “unbounded”></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
----------------------

best regards,
Dariusz Baumann

Hello Dariusz,

I installed your schema into a Tamino 4.1.1.9 database, and inserted the following document:

   <?xml version="1.0" encoding="UTF-8" ?>
   <DOC>
      <OPERATION>
         <DATE>2002-06-05</DATE>
      </OPERATION>
      <OPERATION>
         <DATE>2002-06-06</DATE>
      </OPERATION>
   </DOC>


Your first two queries are okay with this version, but the third query gives the same error you received.

The reason for the error is explained in the error message - “Within document with ino:id = 2 there is a sort key which consist of more than a single value”.
In the third query the sort key is OPERATION/DATE, and as there are two OPERATION elements in the DOC element, the sort key does consist of more than a single value.

(In your first query, OPERATION is selected and sorted - as there is only one DATE element in each OPERATION, this works.)

I don’t know if it is appropriate for your scenario, but you could restrict the sort key in the third query like this:
   DOC[OPERATION/DATE between…] sortby(OPERATION[1]/DATE)

(This will restrict the sortby to the first OPERATION element - which might be complete nonsense for your needs!)

I hope that helps,
Trevor.

Hello Trevor!

First of all, I just would like to thank you for a very quick reply.

I have loaded to my Tamino database the following XML file:

-----------------------------
<?xml version="1.0" encoding="UTF-8" ?>


2002-06-05


2002-06-06


2002-06-01




2002-06-08


2002-06-01


2002-06-05


2002-06-02




2002-06-06


2002-06-01


2002-06-08




2002-06-03



-----------------------------

After that, I have made some queries:

1)
DOC[OPERATION/DATE between “2002-06-01”, “2002-06-10”] sortby(DATE desc)
DOC[OPERATION/DATE between “2002-06-01”, “2002-06-10”] sortby(DATE asc)

2)
DOC[OPERATION/DATE between “2002-06-01”, “2002-06-10”] sortby(OPERATION[1]/DATE)

3)
DOC/OPERATION[DATE between “2002-06-01”, “2002-06-10”] sortby(DATE)
DOC/OPERATION[DATE between “2002-06-01”, “2002-06-10”] sortby(DATE desc)

Unfortunately, all queries returned not sorted data by value node . :frowning:

What query should I make to get sorted data by node ?

In advance, thanks a lot!

best regards,
Dariusz Baumann

Hello Dariusz,

it is starting to get complex, so let’s look at the three queries separately.

I think that the first query might be a bug. In my opinion this query should return you an error of some kind, because the sortby clause does not specify a valid node in the current context.
More precisely, the context is DOC - as there is no DATE node in DOC, you should get an error (or at least a warning).
However, it seems that Tamino is very polite and just quietly ignores the sortby clause.

In order to specify a correct sortby clause for DOC it is necessary to use OPERATION/DATE, which brings us to the second query.
In the second query, the DOC elements are sorted into ascending order of the first OPERATION/DATE element in the document.

With the DOCs that you posted above, the lowest value for the first OPERATION/DATE element is 2002-06-03 (in the fourth DOC), then it is 2002-06-05 (in the first DOC), then 2002-06-06 (in the third DOC) and finally 2002-06-08 (in the second DOC).
In my system the ino:id’s have been allocated sequentially, so I get back the DOC elements in the ino:id order 4, 1, 3, 2 - which is correct.
(Although there are DATE elements with “lower” values, they are not in the first OPERATION element in DOC.)

The third query is rather complex. It returns all the OPERATION elements sorted by DATE. Perhaps the missing bit of information here is that the query sorts the OPERATION elements within the DOC elements, and returns the results in ino:id order for DOC.
So you get back the OPERATION elements for DOC (ino:id=1) sorted into DATE order, then all the OPERATION elements for DOC (ino:id=2") sorted into DATE order, and so on.

Perhaps the easiest thing to do next is to ask this: could you please explain what you would like to accomplish with the sorting? Then we can help you to do it.

Best Regards,
Trevor.

Hello Trevor,

I just want to get sorted data. When I execute the following query:

DOC/OPERATION[DATE between “2002-06-01”, “2002-06-10”] sortby(DATE)

I get the following results:

------------------------------
- xql:result
-
2002-06-01

-
2002-06-05

-
2002-06-06

-
2002-06-01

-
2002-06-02

-
2002-06-05

-
2002-06-08

-
2002-06-01

-
2002-06-06

-
2002-06-08

-
2002-06-03

</xql:result>
------------------------------

Unfortunately, the results are not sorted. I would like to get the following results:

------------------------------
- xql:result
-
2002-06-01

-
2002-06-01

-
2002-06-01

-
2002-06-02

-
2002-06-03

-
2002-06-05

-
2002-06-05

-
2002-06-06

-
2002-06-06

-
2002-06-08

-
2002-06-08

</xql:result>
------------------------------

How I get this results?
What query should I make?

In advance, thanks.

best regards,
Dariusz Baumann

Hi Dariusz,

to get the desired results you should use the following query:
   DOC/OPERATION[DATE between “2002-06-01”, “2002-06-10”] sortall(DATE)

Please note the usage of sortall rather than sortby.

As mentioned previously (though not fully described - sorry), the sortby function sorts within a document (“intra-document sort”).
To sort across documents (“inter-document sort”) it is necessary to use the sortall function.

More details can be found in the Tamino documentation, somewhere around here:

   C:\Program Files\Software AG\Tamino\Tamino 4.1.1.1\Documentation\xqlref\sortbycl.htm


I hope that helps!
Trevor.

Hello Trevor!

Yes, now it works pretty good!
Thanks for support!

best regards,
Dariusz Baumann