on dev help sign in
astype
commitd01b51d0981eaa96ff791d87dd2f38c940800f42 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateMon 15 Apr 2019, 10:30 (8 years ago) parentdf4d60f
2 files changed+13−3
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+12 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+1−3
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+12
@@ -28,6 +28,7 @@ Type expressions.
2828module Squeal.PostgreSQL.Expression.Type
2929 ( TypeExpression (..)
3030 , cast
31+ , astype
3132 , PGTyped (..)
3233 , typedef
3334 , typetable
@@ -100,6 +101,17 @@ cast
100101cast ty x = UnsafeExpression $ parenthesized $
101102 renderSQL x <+> "::" <+> renderSQL ty
102103
104+-- | A safe version of `cast` which just matches a value with its type.
105+--
106+-- >>> printSQL (1 & astype int)
107+-- (1 :: int)
108+astype
109+ :: TypeExpression schemas ty
110+ -- ^ type to specify as
111+ -> Expression outer commons grp schemas params from ty
112+ -- ^ value
113+ -> Expression outer commons grp schemas params from ty
114+astype = cast
103115
104116{-----------------------------------------
105117type expressions
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+1−3
@@ -972,11 +972,9 @@ instance With (Query outer) where
972972>>> import Data.Int (Int32)
973973>>> :{
974974 let
975− one :: Expr ('NotNull 'PGint4)
976− one = 1
977975 query :: Query_ schema () (Sum Int32)
978976 query = withRecursive
979− ( values_ (one `as` #n)
977+ ( values_ (1 `as` #n)
980978 `unionAll`
981979 select_ ((#n + 1) `as` #n)
982980 (from (common #t) & where_ (#n .< 100)) `as` #t )