@@ -41,6 +41,7 @@ module Squeal.PostgreSQL.Definition
4141 , createTable
4242 , createTableIfNotExists
4343 , createView
44+ , createOrReplaceView
4445 , createTypeEnum
4546 , createTypeEnumFrom
4647 , createTypeComposite
@@ -916,6 +917,16 @@ createView alias query = UnsafeDefinition $
916917 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
917918 <+> renderQuery query <> ";"
918919
920+
921+createOrReplaceView
922+ :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
923+ => QualifiedAlias sch vw -- ^ the name of the view to add
924+ -> Query '[] '[] schemas '[] view -- ^ query
925+ -> Definition schemas (Alter sch (CreateOrReplace vw ('View view) schema) schemas)
926+createOrReplaceView alias query = UnsafeDefinition $
927+ "CREATE OR REPLACE VIEW" <+> renderSQL alias <+> "AS"
928+ <+> renderQuery query <> ";"
929+
919930-- | Drop a view.
920931--
921932-- >>> :{
@@ -1163,7 +1174,7 @@ createOrReplaceFunction
11631174 -> NP (TypeExpression schemas) args
11641175 -> TypeExpression schemas ret
11651176 -> FunctionDefinition schemas args ('Returns ret)
1166− -> Definition schemas (Alter sch (Alter fun ('Function args ('Returns ret)) schema) schemas)
1177+ -> Definition schemas (Alter sch (CreateOrReplace fun ('Function args ('Returns ret)) schema) schemas)
11671178createOrReplaceFunction fun args ret fundef = UnsafeDefinition $
11681179 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
11691180 <+> parenthesized (renderCommaSeparated renderSQL args)
@@ -1211,7 +1222,7 @@ createOrReplaceSetFunction
12111222 -> NP (TypeExpression schemas) args
12121223 -> NP (Aliased (TypeExpression schemas)) rets
12131224 -> FunctionDefinition schemas args ('ReturnsTable rets)
1214− -> Definition schemas (Alter sch (Alter fun ('Function args ('ReturnsTable rets)) schema) schemas)
1225+ -> Definition schemas (Alter sch (CreateOrReplace fun ('Function args ('ReturnsTable rets)) schema) schemas)
12151226createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
12161227 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
12171228 <+> parenthesized (renderCommaSeparated renderSQL args)