FreightTrain
asked on
PostgreSQL check if object Exists
I am creating a SQL Script in PostgreSQL. I need it to check if a function exists in the database and if so, I need to execute the drop first and then a CREATE...the pseudo code would be something like this:
IF My_Function() EXISTS
THEN DROP My_Function();
CREATE FUNCTION My_Function();
IF My_Function() EXISTS
THEN DROP My_Function();
CREATE FUNCTION My_Function();
You can just execute DROP function without checking the result of this step - this way the error that will be raised if it does not exist is ignored.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for this. I am learning PostgreSQL with 10 years of SQL Server background and was searching for the if exists() equivilant...I guess you get so caught up in one way, you miss the obvious... Thank YOU!!!! :-)