Re: adjusting primary key

From: John Sidney-Woollett <johnsw(at)wardbrook(dot)com>
To: Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: adjusting primary key
Date: 2006-10-10 14:18:12
Message-ID: 452BABA4.9020109@wardbrook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you could alter the foreign key constraint such that the update on
t1's primary key cascaded to t2, that would help.

However, I'm not sure that you alter the constraint in postgres once
it's created.

Hopefully someone more knowledgeable will be able to respond.

John

Rafal Pietrak wrote:
> Hi All,
>
> I have two tables:
> CREATE TABLE t1 (id int not null unique, info text);
> CREATE TABLE t2 (id int, grp int references t1(id), info text);
>
> Now, at certain point (both tables populated with tousends of records,
> and continuesly referenced by users), I need to adjust the value of an
> ID field of table T1.
>
> How can I do that? On the life system?
>
> Obvious solution like:
> UPDATE t1 SET id=239840 where id=9489;
> or in fact:
> UPDATE t1 SET id=id+10000 where id<1000;
> wouldn't work, regretably.
>
> Naturally I need to have column t2(grp) adjusted accordingly - within a
> single transaction.
>
> Asking this, because currently I've learned, that I can adjust the
> structure of my database (add/remove columns at will, reneme those,
> etc.), but I'm really stuck with 'looking so simple' task.
>
> Today I dump the database and perl-edit whatever's necesary and restore
> the database. But that's not a solution for life system.
>
> Is there a way to get this done? life/on-line?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Staubo 2006-10-10 14:21:50 Re: adjusting primary key
Previous Message Jim C. Nasby 2006-10-10 14:15:52 Re: [PERFORM] Postgre 8.0 Installation - Issues