3

I wrote this query to list Wikidata items that have an RFC identifier:

SELECT ?rfcId ?itemLabel ?classLabel ?item
WHERE 
{
  ?item wdt:P31 ?class.
  ?item wdt:P892 ?rfcId.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?rfcId

A minor problem is that they are sorted in an alphabetic way: 1, 10, 100, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 101, etc.

I tried using ORDER BY xsd:nonNegativeInteger(?rfcId) but it does not work, probably because the property is defined as an "external identifier" rather than as a number.

Can I modify the query to sort results in numeric order (1,2,3,4,5,6,7,8,9,10,etc)?

2

As tipped by Stanislav Kralin and Barry Carter, ORDER BY xsd:integer( is the solution:

SELECT ?rfcId ?itemLabel ?classLabel ?item
WHERE 
{
  ?item wdt:P31 ?class.
  ?item wdt:P892 ?rfcId.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY xsd:integer(?rfcId)

https://tinyurl.com/yazaeneq

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.