Re: Find all foreign keys and dropping them from a script.

From: "Robert Landsmeer" <r(dot)landsmeer(at)wis(dot)nl>
To: "George Young" <gry(at)ll(dot)mit(dot)edu>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Find all foreign keys and dropping them from a script.
Date: 2006-04-19 09:10:32
Message-ID: 50CA25BD6EEA954FA592C097399942E30E463CE7@CM1.wis.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thank you.

This solution does indeed do what I am looking for.

If you ever find the more portable/standard way you described I'll be
happy to hear it but until then I'm happily using the solution you
provided.

Robert

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of George Young
Sent: Tuesday, April 18, 2006 19:59
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] Find all foreign keys and dropping them from a
script.

On Tue, 18 Apr 2006 16:05:48 +0200
"Robert Landsmeer" <r(dot)landsmeer(at)wis(dot)nl> wrote:
> I am having a hard time finding all foreign keys on my database trough
a
> script and then removing them.
>
> The reason I need to do this is that the application I am using has
data
> that has been altered within an update of the product.
>
> To update the database we have a script that will execute all the data
> updates of the product. Since the updater isn't aware of what updates
> need to be done before other updates FK-wise we get all kinds of
errors
> about incorrect data, and the script fails. So we want to drop all
> foreign keys, insert a lot of data, and then re-add all foreign keys.
We
> already have a script that re-adds all foreign keys and also adds the
> new foreign keys for the new product release.

Try:
select c.conname, cl.relname
from pg_constraint c, pg_class cl
where cl.oid=c.conrelid and c.contype='f';

There should be a way to get this from the more portable/standard
'information_schema' schema, but I can't seem to find it right now...

-- George Young

> So at the moment I am looking for a way to get all current FK's trough
a
> JDBC connection. Since a script will auto generate the drop key
scripts
> it would be nice to have a way to do this. But after some searching on
> the internet I could not find a nice way of doing this (if I have
missed
> a resource, please feel free to point me to it :-) ).
>
>
>
> Thanks in advance,
>
> Robert
>
>

--
"Are the gods not just?" "Oh no, child.
What would become of us if they were?" (CSL)

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Talbot-Wilson 2006-04-19 18:49:08 Re: Defining the same relation in another database
Previous Message Guido Barosio 2006-04-19 08:55:04 Re: Defining the same relation in another database