Shouldn't order of GROUP BY be respected?

I am selecting data Grouped By 2 different Tags,
However the results do not appear to be respecting the order of the GROUP BY.

I am executing something similar to:
SELECT * FROM "ServiceStats" WHERE Time > now() - 5m GROUP BY "host", "ServiceName"
The key here is the order of the 2 TAGs in the group by.

Regardless of which order I request the group by … by, I appear to always be returned “ServiceName” first and then “host”. This is making Grafana show its Table in the “wrong” order.

(as you can figure out this is a very minor issue, causing nothing but some cosmetic issues in Grafana)

@paulo I think this is more of a grafana issue than anything else! The database will return those tags in alphabetically sorted order and that is intended behavior.

I agree that it is the “presentation” layer’s responsibility to address which order the columns are shown by.

However,

We were able to solve this issue by accident with a subquery: in the inner query I select the columns (returned in whatever order) and in the outer query I select columns from the inner query in whatever order I want and it is being respected.

1 Like