Re: CASCADING update

From: "Obe, Regina" <robe(dot)dnd(at)cityofboston(dot)gov>
To: "A B" <gentosaker(at)gmail(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: CASCADING update
Date: 2008-10-03 11:02:32
Message-ID: 53F9CF533E1AA14EA1F8C5C08ABC08D204D18979@ZDND.DND.boston.cob
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Be careful. Since it appears you have delete cascade, when you delete
user 2, then all children in the other tables for 2 will be deleted as
well.

I tend to put in delete restrict to prevent accidentally deleting a lot
of important data.

As far as what you are trying to do, unfortunately I don't think there
is an easy way to do this without explicitly updating each table.

Would like to know if there is though.

Thanks,
Regina

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of A B
Sent: Friday, October 03, 2008 5:48 AM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] CASCADING update

I have a base table User (id serial primary key, name text);
and a lot of tables like this
Foo (id integer references User on update cascade on delete cascade,
....);

Assume I have
id =1 name= aaa
id =2 name= bbb

in the user table

and now I wish to remove the user with id=2, but I also want to
update all the Foo tables and set the id to 1 (the other user takes
over all the items), but I do not want to do this by calling update
for each table separatly.
The "on update cascade" sounds like what I need, in some way, but I'm
not sure how to really use it in this case.
Is it possible? If yes, how?

--
Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Steve T 2008-10-03 11:30:13 Re: Forcing order of Joins etc
Previous Message Steve T 2008-10-03 09:59:00 Re: Forcing order of Joins etc