diff --git a/src/AggregateSpecsPlugin.ts b/src/AggregateSpecsPlugin.ts index 2d09416..fe08ee3 100644 --- a/src/AggregateSpecsPlugin.ts +++ b/src/AggregateSpecsPlugin.ts @@ -18,6 +18,8 @@ const AggregateSpecsPlugin: Plugin = (builder) => { builder.hook("build", (build) => { const { pgSql: sql } = build; const isNumberLike = (pgType: PgType): boolean => pgType.category === "N"; + const isIntervalLike = (pgType: PgType): boolean => + pgType.id === INTERVAL_OID; /** Maps from the data type of the column to the data type of the sum aggregate */ /** BigFloat is our fallback type; it should be valid for almost all numeric types */ const convertWithMapAndFallback = ( @@ -48,7 +50,7 @@ const AggregateSpecsPlugin: Plugin = (builder) => { id: "sum", humanLabel: "sum", HumanLabel: "Sum", - isSuitableType: isNumberLike, + isSuitableType: isNumberLike || isIntervalLike, // I've wrapped it in `coalesce` so that it cannot be null sqlAggregateWrap: (sqlFrag) => sql.fragment`coalesce(sum(${sqlFrag}), 0)`, @@ -86,21 +88,21 @@ const AggregateSpecsPlugin: Plugin = (builder) => { id: "min", humanLabel: "minimum", HumanLabel: "Minimum", - isSuitableType: isNumberLike, + isSuitableType: isNumberLike || isIntervalLike, sqlAggregateWrap: (sqlFrag) => sql.fragment`min(${sqlFrag})`, }, { id: "max", humanLabel: "maximum", HumanLabel: "Maximum", - isSuitableType: isNumberLike, + isSuitableType: isNumberLike || isIntervalLike, sqlAggregateWrap: (sqlFrag) => sql.fragment`max(${sqlFrag})`, }, { id: "average", humanLabel: "mean average", HumanLabel: "Mean average", - isSuitableType: isNumberLike, + isSuitableType: isNumberLike || isIntervalLike, sqlAggregateWrap: (sqlFrag) => sql.fragment`avg(${sqlFrag})`, // An AVG(...) ends up more precise than any individual value; see