squeal-postgresql-0.6.0.1: Squeal PostgreSQL Library

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

Squeal.PostgreSQL.Expression.Null

Contents

Description

null expressions and handlers

Synopsis

Null

null_ :: Expr (Null ty) Source #

analagous to Nothing

>>> printSQL null_
NULL

notNull :: NotNull ty --> Null ty Source #

analagous to Just

>>> printSQL $ notNull true
TRUE

unsafeNotNull :: Null ty --> NotNull ty Source #

Analagous to fromJust inverse to notNull, useful when you know an Expression is NotNull, because, for instance, you've filtered out NULL values in a column.

monoNotNull :: (forall null. Expression grp lat with db params from (null ty)) -> Expression grp lat with db params from (NotNull ty) Source #

Some expressions are null polymorphic which may raise inference issues. Use monoNotNull to fix their nullity as NotNull.

coalesce :: FunctionVar (Null ty) (null ty) (null ty) Source #

return the leftmost value which is not NULL

>>> printSQL $ coalesce [null_, true] false
COALESCE(NULL, TRUE, FALSE)

fromNull Source #

Arguments

:: Expression grp lat with db params from (NotNull ty)

what to convert NULL to

-> Expression grp lat with db params from (Null ty) 
-> Expression grp lat with db params from (NotNull ty) 

analagous to fromMaybe using COALESCE

>>> printSQL $ fromNull true null_
COALESCE(NULL, TRUE)

isNull :: Null ty --> null PGbool Source #

>>> printSQL $ null_ & isNull
NULL IS NULL

isNotNull :: Null ty --> null PGbool Source #

>>> printSQL $ null_ & isNotNull
NULL IS NOT NULL

matchNull Source #

Arguments

:: Expression grp lat with db params from nullty

what to convert NULL to

-> (Expression grp lat with db params from (NotNull ty) -> Expression grp lat with db params from nullty)

function to perform when NULL is absent

-> Expression grp lat with db params from (Null ty) 
-> Expression grp lat with db params from nullty 

analagous to maybe using IS NULL

>>> printSQL $ matchNull true not_ null_
CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END

nullIf :: '[NotNull ty, NotNull ty] ---> Null ty Source #

right inverse to fromNull, if its arguments are equal then nullIf gives NULL.

>>> :set -XTypeApplications -XDataKinds
>>> let expr = nullIf (false *: param @1) :: Expression grp lat with db '[ 'NotNull 'PGbool] from ('Null 'PGbool)
>>> printSQL expr
NULLIF(FALSE, ($1 :: bool))