persistent-sql-lifted-0.4.3.1: Monad classes for running queries with Persistent and Esqueleto
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.Persist.Sql.Lifted.Expression.ArrayAggregate.PostgreSQL

Synopsis

Documentation

data AggMode #

Aggregate mode

Constructors

AggModeAll

ALL

AggModeDistinct

DISTINCT

Instances

Instances details
Show AggMode 
Instance details

Defined in Database.Esqueleto.PostgreSQL

arrayAggDistinct :: (PersistField a, PersistField [a]) => SqlExpr (Value a) -> SqlExpr (Value (Maybe [a])) #

(array_agg) Concatenate distinct input values, including NULLs, into an array.

Since: esqueleto-2.5.3

arrayRemove :: SqlExpr (Value [a]) -> SqlExpr (Value a) -> SqlExpr (Value [a]) #

(array_remove) Remove all elements equal to the given value from the array.

Since: esqueleto-2.5.3

arrayRemoveNull :: SqlExpr (Value [Maybe a]) -> SqlExpr (Value [a]) #

Remove NULL values from an array

maybeArray :: (PersistField a, PersistField [a]) => SqlExpr (Value (Maybe [a])) -> SqlExpr (Value [a]) #

Coalesce an array with an empty default value

arrayAggById :: forall val typ. (PersistEntity val, PersistField [typ], PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value [typ]) Source #

Aggregrate the given column with stable ordering (by ID)

This ensures that if you aggregrate two columns:

pure
  ( arrayAggById students StudentFirstName
  , arrayAggById students StudentLastName
  )

The list, if zipped, will be as expected.

See https://stackoverflow.com/a/7317520.

Also replaces the Maybe result with an empty list, because really that's what you always want.

arrayAggByIdMaybe :: forall val typ. (PersistEntity val, PersistField typ) => SqlExpr (Maybe (Entity val)) -> EntityField val typ -> SqlExpr (Value [typ]) Source #

arrayAggById but for a left-outer-joined entity

If you're using (?.) instead of (^.), use this instead of arrayAggById.

arrayAggByMaybe :: forall a b. (PersistField a, PersistField b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value b) -> SqlExpr (Value [a]) Source #

arrayAggBy but for a left-outer-joined entity

If you're using (?.) instead of (^.), use this instead of arrayAggBy.

arrayAggBy :: forall a b. (PersistField [a], PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value [a]) Source #