X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CB89CD97BC for ; Wed, 21 Sep 2005 09:59:13 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82061-07 for ; Wed, 21 Sep 2005 12:59:06 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.206]) by svr1.postgresql.org (Postfix) with ESMTP id 0F4EDD9780 for ; Wed, 21 Sep 2005 09:59:07 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id 40so183623nzk for ; Wed, 21 Sep 2005 05:59:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; b=OSCDXheFp7j2xUO156vjpJNVkNtIHEJnx1Oa1ceizT/pkyi5JJGdG4G1g8k8TEeYszNZGtJLXMYUSWk8P4498UE8PugInh0e/RXmtYEEpgj2JOOZcMLARVoQPh56BCoL8oYbg5RaIz98hrqXcsxWIM3kRCqlwNjHU4P0eSgbA2o= Received: by 10.36.221.19 with SMTP id t19mr398590nzg; Wed, 21 Sep 2005 05:59:11 -0700 (PDT) Received: by 10.36.120.14 with HTTP; Wed, 21 Sep 2005 05:59:11 -0700 (PDT) Message-ID: Date: Wed, 21 Sep 2005 18:29:11 +0530 From: Gnanavel S Reply-To: Gnanavel S To: Joost Kraaijeveld Subject: Re: How to add column from old_table to new_table? Cc: "Pgsql-sql@postgresql.org" In-Reply-To: <1127306186.20038.21.camel@Panoramix> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_403_31313892.1127307551290" References: <1127306186.20038.21.camel@Panoramix> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.294 required=5 tests=[AWL=0.183, HTML_40_50=0.086, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200509/182 X-Sequence-Number: 22729 ------=_Part_403_31313892.1127307551290 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/21/05, Joost Kraaijeveld wrote: > > Hi, > > I have an old_table with two columns: "id" and "old_attribute". I have > new table with the columns "id" and "new_attribute". > > old_table and new_table contain exactly the same id's. Now I want to > copy all the old_attribute from old_table to the corresponding > new_attribute in the new_table Why?. You can simply rename the old_table to new_table including column names (if any). Is that possible in a SQL script (pgadmin or psql console?) and if so, > what is the syntax in this example? > > I have tried something as: > > insert into new_table(new_attribute) > value( select old_attribute from old_table, new_table where old_table.id > =3D new_table_id) > where new_table.id =3D old_table.id You need an update statement and not an insert statement. TIA > > -- > Groeten, > > Joost Kraaijeveld > Askesis B.V. > Molukkenstraat 14 > 6524NB Nijmegen > tel: 024-3888063 / 06-51855277 > fax: 024-3608416 > e-mail: J.Kraaijeveld@Askesis.nl > web: www.askesis.nl > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > -- with regards, S.Gnanavel Satyam Computer Services Ltd. ------=_Part_403_31313892.1127307551290 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/21/05, Joost Kraaijeveld <J.Kraaijeveld@askesis.nl> wrote= :
Hi,

I have an old_table with two columns: "id" and "o= ld_attribute". I have
new table with the columns "id" and= "new_attribute".

old_table and new_table contain exactly = the same id's. Now I want to
copy all the old_attribute from old_table to the corresponding
new_a= ttribute in the new_table

 

Why?. You can simply rename the old_table to new_table= including column names (if any).
 

I= s that possible in a SQL script (pgadmin or psql console?) and if so,
wh= at is the syntax in this example?

I have tried something as:

insert into new_table(new_attribu= te)
value( select old_attribute from old_table, new_table where old_tabl= e.id
=3D new_table_id)
where new_table.id =3D old_table.id

 

You need an update statement and not an insert stateme= nt.


TIA
=
--
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstra= at 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416e-mail: J.Kraaijeveld@Askesis= .nl
web: www.askesis.nl


---------------------------(end of broadcast)----------------------= -----
TIP 2: Don't 'kill -9' the postmaster


--
with regards,
S.Gnanavel
Satyam Computer S= ervices Ltd. ------=_Part_403_31313892.1127307551290--