Re: CREATE TABLE with REFERENCE - Mailing list pgsql-general

From Jonathan Bartlett
Subject Re: CREATE TABLE with REFERENCE
Date
Msg-id Pine.GSU.4.44.0307291259510.29931-100000@eskimo.com
Whole thread Raw
In response to Re: CREATE TABLE with REFERENCE  (Dmitry Tkach <dmitry@openratings.com>)
List pgsql-general
> begin;
> set constraints all immediate;
> update users set id=<new_userid> where login = 'customerA';
> set constraints all deferred;
> delete from users where login = 'custmerA';
> update users set id=<new_userid> where login = 'custmerB';
> delete from users where login = 'customerB';
> insert into users values (<new_id>, 'merged_customer_login', ...);
> commit;
>
> This should take care about rerouting all the depending entries to the
> new user *as long as you have your FKs setup properly*, of course.

Interesting.  After reading this I went back to the docs and found what I
haven't found before:

"Analogous to ON DELETE there is also ON UPDATE which is invoked when a
primary key is changed (updated). The possible actions are the same."

I was under the impression that cascades only applied to deletes.

Something new to chew on.

Thanks!

Jon


pgsql-general by date:

Previous
From: Dmitry Tkach
Date:
Subject: Re: Basic questions before start
Next
From: "scott.marlowe"
Date:
Subject: Re: Basic questions before start