BUG #5563: Odd behavior with aggregate_func(DISTINCT foo ORDER BY foo) - Mailing list pgsql-bugs

From Daniel Grace
Subject BUG #5563: Odd behavior with aggregate_func(DISTINCT foo ORDER BY foo)
Date
Msg-id 201007170004.o6H0485p075061@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #5563: Odd behavior with aggregate_func(DISTINCT foo ORDER BY foo)  (Alex Hunsaker <badalex@gmail.com>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      5563
Logged by:          Daniel Grace
Email address:      dgrace@wingsnw.com
PostgreSQL version: 9.0beta3
Operating system:   Windows XP 32-bit
Description:        Odd behavior with aggregate_func(DISTINCT foo ORDER BY
foo)
Details:

The manual states:
"If DISTINCT is specified in addition to an order_by_clause, then all the
ORDER BY expressions must match regular arguments of the aggregate; that is,
you cannot sort on an expression that is not included in the DISTINCT  list.
"

However, in some circumstances Postgres will fail

DROP TABLE IF EXISTS foo;
CREATE TABLE foo (
    t VARCHAR
);

INSERT INTO foo (t) VALUES ('a'), ('a'), ('b'), ('b'), ('c');

SELECT STRING_AGG(DISTINCT t::TEXT ORDER BY t::TEXT) FROM foo;

pgsql-bugs by date:

Previous
From: "Heinz Groote"
Date:
Subject: BUG #5562: icon "terrestrial globe" much too big
Next
From: "Daniel Grace"
Date:
Subject: BUG #5564: Odd behavior with aggregate_func(DISTINCT foo ORDER BY foo)