Re: moving content of a table to another table

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: moving content of a table to another table
Date: 2006-08-31 14:10:40
Message-ID: 20060831141040.GA7065@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

am Thu, dem 31.08.2006, um 13:05:10 +0000 mailte roy simkes folgendes:
>
>
> Hi,
>
> I'm curious if there is a way to move content of a table to another table? I do
> not like to create lot's of insert commands and then delete them. I'm sure
> there is an easy way to do this. But I would also like to know if there can be
> any problem with a coloumn type of serial. While moving the tables pgsql will
> change the serial to the next value of the sequence or will it leave as it is,
> and when I reach hat number I will have a problem about duplicate entry

You can do something like this:

test=# create table tab1 (id serial, name text);
NOTICE: CREATE TABLE will create implicit sequence "tab1_id_seq" for serial column "tab1.id"
CREATE TABLE
test=*# insert into tab1 values(default, 'andreas');
INSERT 0 1
test=*# insert into tab1 values(default, 'anja');
INSERT 0 1
test=*# create table tab2(id serial, name text);
NOTICE: CREATE TABLE will create implicit sequence "tab2_id_seq" for serial column "tab2.id"
CREATE TABLE
test=*# insert into tab2 (name) select name from tab1;
INSERT 0 2

HTH, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message operationsengineer1 2006-08-31 17:21:21 int4 to varchar length (pgadmin3) issue
Previous Message roy simkes 2006-08-31 13:05:10 moving content of a table to another table