Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

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.


-----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:
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group