Jim Finnerty <jfinn...@amazon.com> writes: > right. It doesn't matter which of the values is returned; however, a > plausible-sounding implementation would case-fold the value, like GROUP BY > LOWER(x), but the case-folded value isn't necessarily one of the original > values and so that could be subtly wrong in the case-insensitive case, and > could in principle be completely wrong in the most general nondeterministic > collation case where the case-folded value isn't even equal to the other > members of the set.
> does the implementation in PG12 ensure that some member of the set of equal > values is chosen as the representative value? Without having actually looked, I'm pretty certain it does. Considerations of data type independence would seem to rule out a hack like applying case folding. There might be case folding happening internally to comparison functions, like citext_cmp, but that wouldn't affect the grouping logic that is going to save aside one of the group of peer values. regards, tom lane