diff --git a/.travis.yml b/.travis.yml index ab81996..9913871 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,8 @@ addons: - postgresql-client - postgresql-server-dev-all + postgresql: "9.6" + env: - GHCVER=7.10 - GHCVER=8.0 diff --git a/src/Database/Esqueleto/PostgreSQL.hs b/src/Database/Esqueleto/PostgreSQL.hs index 76b630e..5f8bb9e 100644 --- a/src/Database/Esqueleto/PostgreSQL.hs +++ b/src/Database/Esqueleto/PostgreSQL.hs @@ -6,6 +6,7 @@ module Database.Esqueleto.PostgreSQL ( arrayAggDistinct , arrayAgg + , arrayRemove , stringAgg , chr , now_ @@ -31,6 +32,13 @@ arrayAggDistinct = arrayAgg . distinct arrayAgg :: SqlExpr (Value a) -> SqlExpr (Value [a]) arrayAgg = unsafeSqlFunction "array_agg" +-- | (@array_remove@) Remove all elements equal to the given value from the +-- array. +-- +-- /Since: 2.5.3/ +arrayRemove :: SqlExpr (Value [a]) -> SqlExpr (Value a) -> SqlExpr (Value [a]) +arrayRemove arr elem = unsafeSqlFunction "array_remove" (arr, elem) + -- | (@string_agg@) Concatenate input values separated by a -- delimiter. -- diff --git a/test/Test.hs b/test/Test.hs index 4cda936..347470f 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1464,6 +1464,14 @@ main = do select . from $ \p -> return (EP.arrayAgg (p ^. PersonName)) liftIO $ L.sort ret `shouldBe` L.sort (map personName people) + it "arrayRemove looks sane" $ + run $ do + let people = [p1, p2, p3, p4, p5] + mapM_ insert people + [Value ret] <- + select . from $ \p -> return (EP.arrayRemove (EP.arrayAgg (p ^. PersonName)) (val "Rachel")) + liftIO $ ret `shouldMatchList` ["John", "Mike", "Livia", "Mitch"] + it "stringAgg looks sane" $ run $ do let people = [p1, p2, p3, p4, p5]