@@ -45,6 +45,7 @@ module Squeal.PostgreSQL.Definition
4545 , createTypeCompositeFrom
4646 , FieldTyped (..)
4747 , createDomain
48+ , createTypeRange
4849 , TableConstraintExpression (..)
4950 , check
5051 , unique
@@ -1032,14 +1033,23 @@ CREATE DOMAIN "positive" AS real CHECK ((("value" > 0) AND "value" IS NOT NULL))
10321033createDomain
10331034 :: (Has sch schemas schema, KnownSymbol dom)
10341035 => QualifiedAlias sch dom
1035− -> (forall nullity. TypeExpression schemas (nullity ty))
1036+ -> (forall null. TypeExpression schemas (null ty))
10361037 -> (forall tab. Condition '[] '[] 'Ungrouped schemas '[] '[tab ::: '["value" ::: 'Null ty]])
1037− -> Definition schemas (Alter sch (Create alias ('Typedef ty) schema) schemas)
1038+ -> Definition schemas (Alter sch (Create dom ('Typedef ty) schema) schemas)
10381039createDomain dom ty condition =
10391040 UnsafeDefinition $ "CREATE DOMAIN" <+> renderSQL dom
10401041 <+> "AS" <+> renderTypeExpression ty
10411042 <+> "CHECK" <+> parenthesized (renderSQL condition) <> ";"
10421043
1044+createTypeRange
1045+ :: (Has sch schemas schema, KnownSymbol range)
1046+ => QualifiedAlias sch range
1047+ -> (forall null. TypeExpression schemas (null ty))
1048+ -> Definition schemas (Alter sch (Create range ('Typedef ('PGrange ty)) schema) schemas)
1049+createTypeRange range ty = UnsafeDefinition $
1050+ "CREATE" <+> "TYPE" <+> renderSQL range <+> "AS" <+> "RANGE" <+>
1051+ parenthesized ("subtype" <+> "=" <+> renderTypeExpression ty)
1052+
10431053-- | Lift `PGTyped` to a field
10441054class FieldTyped schemas ty where
10451055 fieldtype :: Aliased (TypeExpression schemas) ty