pgagg

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package pgagg provides PostgreSQL-specific aggregate functions for sorm projections. Using them on another dialect is a build error returned when the query executes — never silently wrong SQL.

rows, err := sorm.Project[stat](
    sorm.From[models.User](db).GroupBy(u.Country),
    sorm.Field(u.Country),
    sorm.As(pgagg.StringAgg[models.User](u.Name, ", "), "names"),
    sorm.As(pgagg.PercentileCont[models.User](0.5, u.Age), "median_age"),
).All(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayAgg

func ArrayAgg[E any](c sorm.AnyCol) sorm.AggExpr[E, string]

ArrayAgg — array_agg(col).

func BitAnd

func BitAnd[E any](c sorm.AnyCol) sorm.AggExpr[E, int64]

BitAnd / BitOr — bitwise aggregate over integer values.

func BitOr

func BitOr[E any](c sorm.AnyCol) sorm.AggExpr[E, int64]

func BoolAnd

func BoolAnd[E any](c sorm.AnyCol) sorm.AggExpr[E, bool]

BoolAnd — bool_and(col): true when every value is true.

func BoolOr

func BoolOr[E any](c sorm.AnyCol) sorm.AggExpr[E, bool]

BoolOr — bool_or(col): true when at least one value is true.

func Corr

func Corr[E any](y, x sorm.AnyCol) sorm.AggExpr[E, float64]

Corr — corr(y, x): the correlation coefficient.

func CovarPop

func CovarPop[E any](y, x sorm.AnyCol) sorm.AggExpr[E, float64]

CovarPop / CovarSamp — covariance.

func CovarSamp

func CovarSamp[E any](y, x sorm.AnyCol) sorm.AggExpr[E, float64]

func JSONBAgg

func JSONBAgg[E any](c sorm.AnyCol) sorm.AggExpr[E, string]

JSONBAgg — jsonb_agg(col): the group as a JSONB array.

func JSONBObjectAgg

func JSONBObjectAgg[E any](k, v sorm.AnyCol) sorm.AggExpr[E, string]

JSONBObjectAgg — jsonb_object_agg(k, v).

func Mode

func Mode[E any](orderBy sorm.AnyCol) sorm.AggExpr[E, string]

Mode — mode() WITHIN GROUP (ORDER BY col): the most frequent value.

func PercentileCont

func PercentileCont[E any](fraction float64, orderBy sorm.AnyCol) sorm.AggExpr[E, float64]

PercentileCont — percentile_cont(fraction) WITHIN GROUP (ORDER BY col): continuous percentile (0.5 = median, interpolated).

func PercentileDisc

func PercentileDisc[E any](fraction float64, orderBy sorm.AnyCol) sorm.AggExpr[E, float64]

PercentileDisc — percentile_disc(fraction) WITHIN GROUP (ORDER BY col): discrete percentile (an actual value from the set).

func StdDev

func StdDev[E any](c sorm.AnyCol) sorm.AggExpr[E, float64]

Statistical aggregates.

func StdDevPop

func StdDevPop[E any](c sorm.AnyCol) sorm.AggExpr[E, float64]

func StdDevSamp

func StdDevSamp[E any](c sorm.AnyCol) sorm.AggExpr[E, float64]

func StringAgg

func StringAgg[E any](c sorm.AnyCol, sep string) sorm.AggExpr[E, string]

StringAgg — string_agg(col, sep): concatenates values with a separator.

func VarPop

func VarPop[E any](c sorm.AnyCol) sorm.AggExpr[E, float64]

func VarSamp

func VarSamp[E any](c sorm.AnyCol) sorm.AggExpr[E, float64]

func Variance

func Variance[E any](c sorm.AnyCol) sorm.AggExpr[E, float64]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL