squeal-postgresql-0.5.2.0: Squeal PostgreSQL Library

Copyright(c) Eitan Chatav 2019
Maintainereitan@morphism.tech
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Squeal.PostgreSQL.Expression.Collection

Description

Array and composite functions

Synopsis

Documentation

array Source #

Arguments

:: [Expression outer commons grp schemas params from ty]

array elements

-> Expression outer commons grp schemas params from (null (PGvararray ty)) 
>>> printSQL $ array [null_, false, true]
ARRAY[NULL, FALSE, TRUE]

array1 :: (n ~ Length tys, All ((~) ty) tys) => NP (Expression outer commons grp schemas params from) tys -> Expression outer commons grp schemas params from (null (PGfixarray '[n] ty)) Source #

construct a 1-dimensional fixed length array

>>> printSQL $ array1 (null_ :* false *: true)
ARRAY[NULL, FALSE, TRUE]
>>> :type array1 (null_ :* false *: true)
array1 (null_ :* false *: true)
  :: Expression
       outer
       commons
       grp
       schemas
       params
       from
       (null ('PGfixarray '[3] ('Null 'PGbool)))

array2 :: (All ((~) tys) tyss, All SListI tyss, Length tyss ~ n1, All ((~) ty) tys, Length tys ~ n2) => NP (NP (Expression outer commons grp schemas params from)) tyss -> Expression outer commons grp schemas params from (null (PGfixarray '[n1, n2] ty)) Source #

construct a 2-dimensional fixed length array

>>> printSQL $ array2 ((null_ :* false *: true) *: (false :* null_ *: true))
ARRAY[[NULL, FALSE, TRUE], [FALSE, NULL, TRUE]]
>>> :type array2 ((null_ :* false *: true) *: (false :* null_ *: true))
array2 ((null_ :* false *: true) *: (false :* null_ *: true))
  :: Expression
       outer
       commons
       grp
       schemas
       params
       from
       (null ('PGfixarray '[2, 3] ('Null 'PGbool)))

cardinality :: null (PGvararray ty) :--> null PGint8 Source #

>>> printSQL $ cardinality (array [null_, false, true])
cardinality(ARRAY[NULL, FALSE, TRUE])

index Source #

Arguments

:: Word64

index

-> null (PGvararray ty) :--> NullifyType ty 
>>> printSQL $ array [null_, false, true] & index 2
(ARRAY[NULL, FALSE, TRUE])[2]

unnest :: SetOfFunction "unnest" (null (PGvararray ty)) '["unnest" ::: ty] Source #

Expand an array to a set of rows

row Source #

Arguments

:: SListI row 
=> NP (Aliased (Expression outer commons grp schemas params from)) row

zero or more expressions for the row field values

-> Expression outer commons grp schemas params from (null (PGcomposite row)) 

A row constructor is an expression that builds a row value (also called a composite value) using values for its member fields.

>>> :{
type Complex = 'PGcomposite
  '[ "real"      ::: 'NotNull 'PGfloat8
   , "imaginary" ::: 'NotNull 'PGfloat8 ]
:}
>>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression outer commons grp schemas params from ('NotNull Complex)
>>> printSQL i
ROW(0, 1)

field Source #

Arguments

:: (Has sch schemas schema, Has tydef schema (Typedef (PGcomposite row)), Has field row ty) 
=> QualifiedAlias sch tydef

row type

-> Alias field

field name

-> Expression outer commons grp schemas params from (NotNull (PGcomposite row)) 
-> Expression outer commons grp schemas params from ty 
>>> :{
type Complex = 'PGcomposite
  '[ "real"      ::: 'NotNull 'PGfloat8
   , "imaginary" ::: 'NotNull 'PGfloat8 ]
type Schema = '["complex" ::: 'Typedef Complex]
:}
>>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression outer '[] grp (Public Schema) from params ('NotNull Complex)
>>> printSQL $ i & field #complex #imaginary
(ROW(0, 1)::"complex")."imaginary"