an aggregation function for PostgreSQL