on dev help sign in
add coalesce
commit280400e1eb92bdc9188bc128f3618be11b4fddcf authorEitan Chatav <eitan.chatav@gmail.com> dateThu 15 Jun 2017, 14:10 (9 years ago) parent128e2f1
1 file changed+11
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+11
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+11
@@ -129,6 +129,17 @@ instance Boolean (Expression params tables ('NotNull 'PGBool)) where
129129type instance BooleanOf (Expression params tables ty) =
130130 Expression params tables ('NotNull 'PGBool)
131131
132+coalesce
133+ :: [Expression params tables ('Null x)]
134+ -> Expression params tables ('NotNull x)
135+ -> Expression params tables ('NotNull x)
136+coalesce nulls notNull = UnsafeExpression $ mconcat
137+ [ "COALESCE("
138+ , ByteString.intercalate ", " $ map renderExpression nulls
139+ , ", ", renderExpression notNull
140+ , ")"
141+ ]
142+
132143caseWhenThenElse
133144 :: [(Expression params tables ('NotNull 'PGBool), Expression params tables ty)]
134145 -> Expression params tables ty