Sample code for automatic summary tables in PostgreSQL