Re: [ADMIN] Dropping foreign key only if it exists

2011-04-20 Thread Lukasz Brodziak
The function: CREATE OR REPLACE FUNCTION dropfk() RETURNS integer AS $BODY$ DECLARE isDropped INTEGER; BEGIN IF exists(select 1 from pg_constraint where conname = 'my_fk') THEN ALTER TABLE my_table DROP CONSTRAINT my_fk CASCADE; isDropped = 1; ELSE isDropped = 0; END IF; return isDropped; END; $

Re: [ADMIN] Dropping foreign key only if it exists

2011-04-20 Thread Viktor Bojović
use this table: http://www.postgresql.org/docs/8.3/static/catalog-pg-constraint.html to check if it exists. On Wed, Apr 20, 2011 at 12:46 PM, Lukasz Brodziak wrote: > Hello, > > Is there a way of dropping a FK only if it exists. The thing is that I > don't know if client has this FK on the table

[ADMIN] Dropping foreign key only if it exists

2011-04-20 Thread Lukasz Brodziak
Hello, Is there a way of dropping a FK only if it exists. The thing is that I don't know if client has this FK on the table or not. -- Łukasz Brodziak "What if everyting around You isn't quite as it seems, What if all the world You think You know is an inelaborate dream When You look at Your ref