on dev help sign in
Merge pull request #104 from morphismtech/dev-unnest

Dev unnest

commit3b9e0f4d4f7dcae0b4d2505f0da78ecc8b1c6d2f authorEitan Chatav <eitan.chatav@gmail.com> dateThu 28 Feb 2019, 08:53 (8 years ago) parentea80ad20d0614a
2 files changed+15
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+8 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+7
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+8
@@ -47,6 +47,7 @@ module Squeal.PostgreSQL.Expression
4747 , nullIf
4848 -- ** Collections
4949 , array
50+ , cardinality
5051 , index
5152 , row
5253 , field
@@ -483,6 +484,13 @@ array
483484array xs = UnsafeExpression $
484485 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
485486
487+-- | >>> printSQL $ cardinality (array [null_, false, true])
488+-- cardinality(ARRAY[NULL, FALSE, TRUE])
489+cardinality
490+ :: Expression outer grp commons schemas params from (nullity ('PGvararray ty))
491+ -> Expression outer grp commons schemas params from (nullity 'PGint8)
492+cardinality = unsafeFunction "cardinality"
493+
486494-- | >>> printSQL $ array [null_, false, true] & index 2
487495-- (ARRAY[NULL, FALSE, TRUE])[2]
488496index
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+7
@@ -52,6 +52,8 @@ module Squeal.PostgreSQL.Query
5252 -- ** With
5353 , With (..)
5454 , CommonTableExpression (..)
55+ -- ** Unnest
56+ , unnest
5557 -- ** Json
5658 , jsonEach
5759 , jsonbEach
@@ -718,6 +720,11 @@ unsafeSetOfFunction
718720unsafeSetOfFunction fun expr = UnsafeQuery $
719721 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
720722
723+unnest
724+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity ('PGvararray ty))
725+ -> Query outer commons schemas params '[ "unnest" ::: ty ]
726+unnest = unsafeSetOfFunction "unnest"
727+
721728-- | Expands the outermost JSON object into a set of key/value pairs.
722729jsonEach
723730 :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object