diff --git a/esqueleto.cabal b/esqueleto.cabal index debe59f..c22f170 100644 --- a/esqueleto.cabal +++ b/esqueleto.cabal @@ -1,5 +1,5 @@ name: esqueleto -version: 2.5.2 +version: 2.5.3 synopsis: Type-safe EDSL for SQL queries on persistent backends. homepage: https://github.com/bitemyapp/esqueleto license: BSD3 diff --git a/src/Database/Esqueleto/PostgreSQL.hs b/src/Database/Esqueleto/PostgreSQL.hs index 2e9f8d8..76b630e 100644 --- a/src/Database/Esqueleto/PostgreSQL.hs +++ b/src/Database/Esqueleto/PostgreSQL.hs @@ -4,7 +4,8 @@ -- -- /Since: 2.2.8/ module Database.Esqueleto.PostgreSQL - ( arrayAgg + ( arrayAggDistinct + , arrayAgg , stringAgg , chr , now_ @@ -14,6 +15,15 @@ import Database.Esqueleto.Internal.Language import Database.Esqueleto.Internal.Sql import Data.Time.Clock (UTCTime) +-- | (@array_agg@) Concatenate distinct input values, including @NULL@s, into +-- an array. +-- +-- /Since: 2.5.3/ +arrayAggDistinct :: SqlExpr (Value a) -> SqlExpr (Value [a]) +arrayAggDistinct = arrayAgg . distinct + where + distinct = unsafeSqlBinOp " " (unsafeSqlValue "DISTINCT") + -- | (@array_agg@) Concatenate input values, including @NULL@s, -- into an array. -- diff --git a/test/Test.hs b/test/Test.hs index f52c7f5..4cda936 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1446,6 +1446,16 @@ main = do #else (return () :: IO ()) + it "arrayAggDistinct looks sane" $ + run $ do + let people1 = fmap (\p -> p { personName = "John" }) [p1, p2, p3] + people2 = fmap (\p -> p { personName = "Rachel" }) [p4, p5] + mapM_ insert $ people1 <> people2 + [Value ret] <- + select . from $ \p -> return (EP.arrayAggDistinct (p ^. PersonName)) + liftIO $ L.sort ret `shouldBe` ["John", "Rachel"] + + it "arrayAgg looks sane" $ run $ do let people = [p1, p2, p3, p4, p5]