From: | "Oleg Lebedev" <oleglebedev(at)waterford(dot)org> |
---|---|
To: | "Oleg Lebedev" <oleglebedev(at)waterford(dot)org>, "Richard Huxton" <dev(at)archonet(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Modifying FK constraints |
Date: | 2004-11-10 18:33:07 |
Message-ID: | BA823062DCC29644992A83C3C5AF9FCBE332@wistomail01.waterford.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In order to find all FK declared on a table I query tg_trigger view. The
query lists all FKs declared on the table as well as all the ones
referencing the table. I noticed that FKs that are declared on the table
have pgtype equal to 21, and FKs referencing the table have pgtype 9 or
17.
The following query lists all the FKs declared table 'objective'. Is
this the right way to do this?
select t.tgconstrname, src.relname, dest.relname, t.tgtype
from pg_trigger t, pg_class src, pg_class dest
where t.tgrelid=src.oid
and t.tgconstrrelid=dest.oid
and t.tgisconstraint = 't'
and t.tgtype=21
and src.relname='objective';
Thanks.
Oleg
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Oleg Lebedev
Sent: Wednesday, November 10, 2004 10:37 AM
To: Richard Huxton
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Modifying FK constraints
Thanks, but the problem here is that I have multiple replicated
databases with the same schema and each of them contains numerous
tables. So, dropping and re-creating FK constraints manualy is not
feasible, and I am trying to automate this process.
Each table contains a primary key column "objectid", so this should make
it simpler to apply the same procedure to all tables.
So, what I want to do is:
FOR EACH TABLE
1. Find out if there is an FK referencing its "objectid" column
2. If there is one, then either drop and recreate the FK or
modify FKs system property to force cascading of updates. I would rather
prefer updating the system table.
So, I would need to know answers to the following questions:
1. How can I find out what FKs reference a the given column based on the
system table information? 2. What system table do I need to update to
force an FK constraint to cascade updates?
Thanks.
Oleg
-----Original Message-----
From: Richard Huxton [mailto:dev(at)archonet(dot)com]
Sent: Wednesday, November 10, 2004 10:23 AM
To: Oleg Lebedev
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Modifying FK constraints
Oleg Lebedev wrote:
> Greetings.
>
> Is it possible to modify a foreign key constraint and force it to
> cascade on update? If there is no such SQL command, then is it
> possible to update some system tables to accomplish this?
BEGIN;
ALTER TABLE t1 DROP CONSTRAINT ...
ALTER TABLE t1 ADD CONSTRAINT ...
COMMIT;
Note that this will trigger a re-examination of all the values to check
the constraint is valid.
Also you may have to quote constraint names. If they are generated as $1
you will need to refer to them as "$1".
Full details in the "SQL Commands" chapter under "ALTER TABLE"
--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 3: 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
From | Date | Subject | |
---|---|---|---|
Next Message | Goutam Paruchuri | 2004-11-10 18:38:18 | Re: Error connecting using pgadmin from different computer |
Previous Message | Marc G. Fournier | 2004-11-10 18:24:32 | Re: Important Info on comp.databases.postgresql.general |