@@ -46,9 +46,9 @@ module Squeal.PostgreSQL.Definition
4646 , createTypeEnumFrom
4747 , createTypeComposite
4848 , createTypeCompositeFrom
49− , FieldTyped (..)
50− , createDomain
5149 , createTypeRange
50+ , createDomain
51+ , FieldTyped (..)
5252 , createIndex
5353 , createIndexIfNotExists
5454 , IndexMethod (..)
@@ -83,7 +83,9 @@ module Squeal.PostgreSQL.Definition
8383 , dropIndex
8484 , dropIndexIfExists
8585 , dropFunction
86+ , dropFunctionIfExists
8687 , dropOperator
88+ , dropOperatorIfExists
8789 -- ** Alter
8890 , alterTable
8991 , alterTableRename
@@ -931,7 +933,7 @@ in printSQL definition
931933CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
932934-}
933935createView
934− :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
936+ :: (Has sch schemas schema, KnownSymbol vw)
935937 => QualifiedAlias sch vw -- ^ the name of the view to add
936938 -> Query '[] '[] schemas '[] view -- ^ query
937939 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
@@ -939,9 +941,8 @@ createView alias query = UnsafeDefinition $
939941 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
940942 <+> renderQuery query <> ";"
941943
942−
943944createOrReplaceView
944− :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
945+ :: (Has sch schemas schema, KnownSymbol vw)
945946 => QualifiedAlias sch vw -- ^ the name of the view to add
946947 -> Query '[] '[] schemas '[] view -- ^ query
947948 -> Definition schemas (Alter sch (CreateOrReplace vw ('View view) schema) schemas)
@@ -1338,21 +1339,37 @@ createRightOp fun x = UnsafeDefinition $
13381339 , "LEFTARG" <+> "=" <+> renderSQL x ]
13391340
13401341dropFunction
1341− :: (Has sch schemas schema, Has fun schema ('Function (args '::--> ret)))
1342+ :: (Has sch schemas schema, KnownSymbol fun)
13421343 => QualifiedAlias sch fun
13431344 -- ^ name of the user defined function
1344− -> Definition schemas (Alter sch (Drop fun schema) schemas)
1345+ -> Definition schemas (Alter sch (DropSchemum fun 'Function schema) schemas)
13451346dropFunction fun = UnsafeDefinition $
13461347 "DROP" <+> "FUNCTION" <+> renderSQL fun <> ";"
13471348
1349+dropFunctionIfExists
1350+ :: (Has sch schemas schema, KnownSymbol fun)
1351+ => QualifiedAlias sch fun
1352+ -- ^ name of the user defined function
1353+ -> Definition schemas (Alter sch (DropSchemumIfExists fun 'Function schema) schemas)
1354+dropFunctionIfExists fun = UnsafeDefinition $
1355+ "DROP FUNCTION IF EXISTS" <+> renderSQL fun <> ";"
1356+
13481357dropOperator
1349− :: (Has sch schemas schema, Has op schema ('Operator oper))
1358+ :: (Has sch schemas schema, KnownSymbol op)
13501359 => QualifiedAlias sch op
13511360 -- ^ name of the user defined operator
1352− -> Definition schemas (Alter sch (Drop op schema) schemas)
1361+ -> Definition schemas (Alter sch (DropSchemum op 'Operator schema) schemas)
13531362dropOperator op = UnsafeDefinition $
13541363 "DROP" <+> "OPERATOR" <+> renderSQL op <> ";"
13551364
1365+dropOperatorIfExists
1366+ :: (Has sch schemas schema, KnownSymbol op)
1367+ => QualifiedAlias sch op
1368+ -- ^ name of the user defined operator
1369+ -> Definition schemas (Alter sch (DropSchemumIfExists op 'Operator schema) schemas)
1370+dropOperatorIfExists op = UnsafeDefinition $
1371+ "DROP OPERATOR IF EXISTS" <+> renderSQL op <> ";"
1372+
13561373newtype FunctionDefinition schemas args ret = UnsafeFunctionDefinition
13571374 { renderFunctionDefinition :: ByteString }
13581375 deriving (Eq,Show,GHC.Generic,NFData)