-
Notifications
You must be signed in to change notification settings - Fork 6
Tilda Database functions: Aggregates
Laurent Hasson edited this page Sep 17, 2019
·
3 revisions
<-- Common Helper Database Functions
Source code in PostgreSQL.helpers-start.sql
Postgres lacks some common aggregates out of the box. However, implementing them is easy!
An implementation is provided for FIRST/LAST aggregates.
select company
, FIRST("dateOfBirth") as "eldestDob"
, LAST("dateOfBirth) "youngestDob"
from Employee
group by company
order by "dateOfBirth" desc
Postgres support powerful arrays and so, when you use it, you may want to aggregate arrays together. The standard aggregate returns an array of arrays. This one returns a flat array that contains all the elements from the aggregated arrays.
select company
, ARRAY_CAT_AGG(distinct "hireDates") as "hireDates"
from Employee
group by company
order by "hireDates" desc