?
Solved

PostgreSQL check if object Exists

Posted on 2007-10-11
3
Medium Priority
?
5,954 Views
Last Modified: 2008-01-09
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();
0
Comment
Question by:FreightTrain
3 Comments
 
LVL 15

Expert Comment

by:m1tk4
ID: 20062380
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.
0
 
LVL 22

Accepted Solution

by:
earth man2 earned 2000 total points
ID: 20064374
m1tk4 has missed the blindingly obvious...
this is such a common action that this facility is built into the create function command.
simply

CREATE OR REPLACE FUNCTION()....
0
 

Author Comment

by:FreightTrain
ID: 20064528
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!!!!  :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question