Usage of arrays in aggregations

If you get to know them you will simply love them – I mean ARRAYs in PostgreSQL. And also in some situations you simply cannot live without them – at least in PostgreSQL. Here are some examples how to use them in real life. (still in TODO) Aggregations...

Count according to condition

In PostgreSQL command like “SELECT count( column IS NOT NULL ) FROM table” is not working. But you can always use SUM. SUM + CAST: SELECT sum( (column IS NOT NULL)::INT ) FROM table or SUM + CASE: SELECT sum( CASE WHEN column IS NOT NULL THEN 1 ELSE 0 END)...