@@ -41,6 +41,7 @@ module Squeal.PostgreSQL.Definition
41 , createTable
41 , createTable
42 , createTableIfNotExists
42 , createTableIfNotExists
43 , createView
43 , createView
44+ , createOrReplaceView
44 , createTypeEnum
45 , createTypeEnum
45 , createTypeEnumFrom
46 , createTypeEnumFrom
46 , createTypeComposite
47 , createTypeComposite
@@ -916,6 +917,16 @@ createView alias query = UnsafeDefinition $
916 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
917 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
917 <+> renderQuery query <> ";"
918 <+> renderQuery query <> ";"
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 <> ";"
919-- | Drop a view.
930-- | Drop a view.
@@ -1163,7 +1174,7 @@ createOrReplaceFunction
1163 -> NP (TypeExpression schemas) args
1174 -> NP (TypeExpression schemas) args
1164 -> TypeExpression schemas ret
1175 -> TypeExpression schemas ret
1165 -> FunctionDefinition schemas args ('Returns ret)
1176 -> 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)
1167createOrReplaceFunction fun args ret fundef = UnsafeDefinition $
1178createOrReplaceFunction fun args ret fundef = UnsafeDefinition $
1168 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
1179 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
1169 <+> parenthesized (renderCommaSeparated renderSQL args)
1180 <+> parenthesized (renderCommaSeparated renderSQL args)
@@ -1211,7 +1222,7 @@ createOrReplaceSetFunction
1211 -> NP (TypeExpression schemas) args
1222 -> NP (TypeExpression schemas) args
1212 -> NP (Aliased (TypeExpression schemas)) rets
1223 -> NP (Aliased (TypeExpression schemas)) rets
1213 -> FunctionDefinition schemas args ('ReturnsTable rets)
1224 -> 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)
1215createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
1226createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
1216 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
1227 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
1217 <+> parenthesized (renderCommaSeparated renderSQL args)
1228 <+> parenthesized (renderCommaSeparated renderSQL args)