pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
recreating table and foreign keys
4+ messages / 2 participants
[nested] [flat]

* recreating table and foreign keys
@ 2002-12-03 09:03  Tomasz Myrta <jasiek@klaster.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Tomasz Myrta @ 2002-12-03 09:03 UTC (permalink / raw)
  To: pgsql-sql

Hi
I use Postgresql 7.2.2.
Sometimes I have to remove a column from my tables (psql):
1. alter table master_table rename to x;
2. \i tables.sql
3. insert into master_table select f1,f2,... from x
4. drop table x

I think, foreign keys referring from detail_table(s) to master_table 
have gone.
How to recreate foreign keys? I want to keep my database in better 
integrity, than now...

Tomasz Myrta







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: recreating table and foreign keys
@ 2002-12-03 12:29  Tomasz Myrta <jasiek@klaster.net>
  parent: Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tomasz Myrta @ 2002-12-03 12:29 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; Tomasz Myrta <jasiek@klaster.net>; +Cc: pgsql-sql

> You'll probably end up using ALTER TABLE ADD CONSTRAINT to add the
> constraints to the new master_table.  It's possible that you might 
> be able to hack something with the system tables, but that sounds 
> dangerous.  Or you can upgrade to 7.3 which lets you run alter table 
> drop column. :)
If it is the only way, I can create >20 "alter table add constraint...", but 
is rather a boring finish :-(
I found, I can dump database - data only. After this I can create all tables 
and restore data.

Any other solution?
Tomasz Myrta



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: recreating table and foreign keys
@ 2002-12-03 16:31  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Tomasz Myrta <jasiek@klaster.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Stephan Szabo @ 2002-12-03 16:31 UTC (permalink / raw)
  To: Tomasz Myrta <jasiek@klaster.net>; +Cc: pgsql-sql


On Tue, 3 Dec 2002, Tomasz Myrta wrote:

> Hi
> I use Postgresql 7.2.2.
> Sometimes I have to remove a column from my tables (psql):
> 1. alter table master_table rename to x;
> 2. \i tables.sql
> 3. insert into master_table select f1,f2,... from x
> 4. drop table x
>
> I think, foreign keys referring from detail_table(s) to master_table
> have gone.
> How to recreate foreign keys? I want to keep my database in better
> integrity, than now...

You'll probably end up using ALTER TABLE ADD CONSTRAINT to add the
constraints to the new master_table.  It's possible that you might be able
to hack something with the system tables, but that sounds dangerous.  Or
you can upgrade to 7.3 which lets you run alter table drop column. :)





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: recreating table and foreign keys
@ 2002-12-03 19:55  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Tomasz Myrta <jasiek@klaster.net>
  0 siblings, 0 replies; 4+ messages in thread

From: Stephan Szabo @ 2002-12-03 19:55 UTC (permalink / raw)
  To: Tomasz Myrta <jasiek@klaster.net>; +Cc: pgsql-sql


On Tue, 3 Dec 2002, Tomasz Myrta wrote:

> > You'll probably end up using ALTER TABLE ADD CONSTRAINT to add the
> > constraints to the new master_table.  It's possible that you might
> > be able to hack something with the system tables, but that sounds
> > dangerous.  Or you can upgrade to 7.3 which lets you run alter table
> > drop column. :)
> If it is the only way, I can create >20 "alter table add constraint...", but
> is rather a boring finish :-(
> I found, I can dump database - data only. After this I can create all tables
> and restore data.

Yeah, dump and restore is generally a pretty big thing though.

> Any other solution?

You might be able to write a function that would duplicate constraints
from the table you want to dispose of to the new table, but it might be
hairy.  If you do this alot, you might want to upgrade to 7.3 (which
requires one dump and reload).




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-12-03 19:55 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-12-03 09:03 recreating table and foreign keys Tomasz Myrta <jasiek@klaster.net>
2002-12-03 16:31 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-12-03 12:29   ` Tomasz Myrta <jasiek@klaster.net>
2002-12-03 19:55     ` Stephan Szabo <sszabo@megazone23.bigpanda.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox