Aggregate a single table.
-
Create a target table that will hold the aggregated data.
-
Create expressions for the groups and aggregtes.
-
Author a JSON file describing the groups and aggregates.
-
Run the
denorm create-agg
command to generate SQL DDL for triggers and functions. -
Apply the generated SQL to the database.
Now the target table will be kept up-to-date whenever the relevant tables change.
For a full working example, see Aggregate example.
See Aggregate config for documentation of all options.
The target table must have a column _count bigint
. This tracks the number of
source records, so that aggregated records can be removed.
The grouping key of the aggregate.
Each aggregate defines it's value, using the variable sign
to determine the
sign of operation, e.g. sum(sign)
.
It also defines a scalar combining expression, e.g.
existing.example = excluded.example
.
A filter expression may be specified.
ID is used to name database objects.
Database objects are created in the schema if given. Otherwise they will be created in the default schema.
There are two consistency modes.
The target is updated at the end of the statement.
The target is updated at the end of the transaction.
Deferring work involves overhead. It is useful for avoiding lock contention on the target table.