Link to home
Start Free TrialLog in
Avatar of FreightTrain
FreightTrainFlag for United States of America

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();
Avatar of m1tk4
m1tk4
Flag of United States of America image

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
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FreightTrain

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!!!!  :-)