Wrong sorting order of numerical strings

We would like to be able to filter/sort by appVersion which has the following format:

‘3.200.0’
‘3.199.0’
‘3.25.0’

These are being sent as strings. The problem is that when I run this query I can see that New Relic doesn’t sort them as number but as strings instead which leads to wrong results.

The query used is:

SELECT count(*) FROM MobileSession FACET appVersion, numeric(appBuild) LIMIT 1000 WHERE osName = ‘iOS’ SINCE 1 week ago

The correct output should be this:

But if I sort by app version I get this instead:

Again if sorted by appBuild (which is also a string) I get wrong results:

I have also tried using the numeric(…) on the facet string properties but still got wrong results.

Hi @apinho1!

This is a commonly requested feature request as NRQL does not currently support ORDER BY. Per our documentation:

The facets are sorted in descending order by the first field you provide in the SELECT clause. If you are faceting on attributes with more than 1,000 unique values, Insights picks a subset of facet values and sorts them according to the query type.

https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/nrql-syntax-components-functions#sel-facet

1 Like