So the "distinct id" becomes "distinct (id, random())" and in the end the "random()" column is hidden in the output. If the standard requires the presence of the column in the select list, this query should not compile. If it compiles, it breaks the standard, but should work as expected, because the substitution "id -> (id, random())" is not what is expressed in the query.
If we would like to do this "properly", we should write something like this:
Code:
select first n distinct id from (
select id, random() as r from a order by r
) q
Because this is the real point of Ania's query (without first n there would be no reason to order by anything in the subquery). But in Ingres we cannot order rows in subqueries. My point is, the unexpected behaviour should still be considered as a bug or at least as an issue in the standard.