Today, on irc, someone asked interesting question. Basically she ran a query like: select a, b, c, d, e, f from table order by a then, she processed the query to get, for each a array of unique values of b, c, d, ...

So, couple of days ago, some guy, from Periscope company wrote a blogpost about getting number of distinct elements, per group, faster using subqueries. This was then submitted to Hacker News and r/Programming on Reddit. Then, the original authors submitted second blogpost ...

Let's assume you have some simple database with "articles" - each article can be in many "categories". And now you want to get list of all articles in given set of categories. Standard approach: select a.* from ...

Robert Haas wrote, and Tom Lane committed (on 2nd of August) patch which adds interesting capability: Log Message: ----------- Add ALTER TABLE ... ALTER COLUMN ... SET STATISTICS DISTINCT   Robert Haas Log message is rather terse, so what does it exactly do?

Every so often you need to get list of unique elements in some column. The standard way to do it is: select distinct column from table; or select column from table group by column; The only problem is that it's slow - as it ...

Today Tom Lane committed patch which gives DISTINCT ability to use hash aggregate - just like GROUP BY.

When I was working for one of customers we found some strange thing. We needed to found number of distinct sessions per day. Table layout was very simple: