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

Re: replacing tables

From: Joel Burton <jburton(at)scw(dot)org>
To: Mark Byerley <mrbyerle(at)uwaterloo(dot)ca>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: replacing tables
Date: 2001-04-08 09:34:48
Message-ID: Pine.LNX.4.21.0104080532440.19671-100000@olympus.scw.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Fri, 6 Apr 2001, Mark Byerley wrote:

> I have one table named temp and another table which I have added a few 
> fields to - let's call it temp_test. It has all the same fields as table 
> temp except it also has a birthdate field just recently added. Table temp 
> has many indexes and sequences created to handle certain fields and what 
> not. What I would like to know is simply if I insert into temp_test select 
> * from temp and then drop table temp and create table temp as select * from 
> temp_test, will I lose the indexes and sequences attributed to the original 
> table temp?
> thanks for any help on this one.

As long as you don't drop table temp itself, you'll be fine removing its
records and inserting from another table.

(In fact, this is a good way to handle this problem. If you have
referential integrity, you won't want to actually DELETE FROM TABLE
temp, as that would call your ref integrity routines. Instead TRUNCATE
temp, which removes all records very quickly, and ignores ref integrity.)

-- 
Joel Burton   <jburton(at)scw(dot)org>
Director of Information Systems, Support Center of Washington


In response to

pgsql-novice by date

Next:From: Tom StricklandDate: 2001-04-08 16:09:40
Subject: table version history
Previous:From: Louis-David MitterrandDate: 2001-04-08 09:10:06
Subject: Re: [GENERAL] Re: Permissons on database

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