Why DISTINCT ON
is sorting the rows? E.g. the query
SELECT DISTINCT ON (a) a
FROM (
VALUES (2), (3), (1)
) x(a);
will have the result
1
2
3
while without DISTINCT ON
SELECT a
FROM (
VALUES (2), (3), (1)
) x(a);
I'll get the correct order
2
3
1
How can I preserve the natural order of defined values? By "natural order" I mean "the order in which the values were defined". I understand that DBMS may change the order if I don't specify it explicitly with an ORDER BY
, but I was not expecting that DISTINCT ON
my interfere in this way.