Add stringAgg to PostgreSQL module (fixes #98).
This commit is contained in:
parent
6c63f2c5ac
commit
3bfa1a9a43
@ -5,8 +5,11 @@
|
||||
-- /Since: 2.2.8/
|
||||
module Database.Esqueleto.PostgreSQL
|
||||
( arrayAgg
|
||||
, stringAgg
|
||||
) where
|
||||
|
||||
import Data.String (IsString)
|
||||
|
||||
import Database.Esqueleto.Internal.Language
|
||||
import Database.Esqueleto.Internal.Sql
|
||||
|
||||
@ -17,3 +20,15 @@ import Database.Esqueleto.Internal.Sql
|
||||
-- /Since: 2.2.8/
|
||||
arrayAgg :: SqlExpr (Value a) -> SqlExpr (Value [a])
|
||||
arrayAgg = unsafeSqlFunction "array_agg"
|
||||
|
||||
|
||||
-- | (@string_agg@) Concatenate input values separated by a
|
||||
-- delimiter.
|
||||
--
|
||||
-- /Since: 2.2.8/
|
||||
stringAgg
|
||||
:: IsString s
|
||||
=> SqlExpr (Value s) -- ^ Input values.
|
||||
-> SqlExpr (Value s) -- ^ Delimiter.
|
||||
-> SqlExpr (Value s) -- ^ Concatenation.
|
||||
stringAgg expr delim = unsafeSqlFunction "string_agg" (expr, delim)
|
||||
|
||||
10
test/Test.hs
10
test/Test.hs
@ -1330,6 +1330,16 @@ main = do
|
||||
from $ \p -> do
|
||||
return (EP.arrayAgg (p ^. PersonName))
|
||||
liftIO $ L.sort ret `shouldBe` L.sort (map personName people)
|
||||
|
||||
it "stringAgg looks sane" $
|
||||
run $ do
|
||||
let people = [p1, p2, p3, p4, p5]
|
||||
mapM_ insert people
|
||||
[Value ret] <-
|
||||
select $
|
||||
from $ \p -> do
|
||||
return (EP.stringAgg (p ^. PersonName) (val " "))
|
||||
liftIO $ L.sort (words ret) `shouldBe` L.sort (map personName people)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user