Adding chr to the list of Postgresql functions.

This commit is contained in:
Kris Jenkins 2015-08-02 22:10:24 +01:00
parent 22ba061e8b
commit fa1d1c8887
2 changed files with 15 additions and 1 deletions

View File

@ -6,6 +6,7 @@
module Database.Esqueleto.PostgreSQL
( arrayAgg
, stringAgg
, chr
) where
import Data.String (IsString)
@ -32,3 +33,12 @@ stringAgg
-> SqlExpr (Value s) -- ^ Delimiter.
-> SqlExpr (Value s) -- ^ Concatenation.
stringAgg expr delim = unsafeSqlFunction "string_agg" (expr, delim)
-- | (@chr@) Translate the given integer to a character. (Note the result will
-- depend on the character set of your database.)
--
-- /Since: 2.2.11/
chr :: IsString s
=> SqlExpr (Value Int) -> SqlExpr (Value s)
chr = unsafeSqlFunction "chr"

View File

@ -1356,8 +1356,12 @@ main = do
from $ \p -> do
return (EP.stringAgg (p ^. PersonName) (val " "))
liftIO $ L.sort (words ret) `shouldBe` L.sort (map personName people)
#endif
it "chr looks sane" $
run $ do
[Value (ret :: String)] <- select $ return (EP.chr (val 65))
liftIO $ ret `shouldBe` "A"
#endif
----------------------------------------------------------------------