pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gnanavel S <s.gnanavel@gmail.com>
To: Joost Kraaijeveld <J.Kraaijeveld@askesis.nl>
Cc: Pgsql-sql@postgresql.org <Pgsql-sql@postgresql.org>
Subject: Re: How to add column from old_table to new_table?
Date: Wed, 21 Sep 2005 18:29:11 +0530
Message-ID: <eec3b03c0509210559253d2465@mail.gmail.com> (raw)
In-Reply-To: <1127306186.20038.21.camel@Panoramix>
References: <1127306186.20038.21.camel@Panoramix>

On 9/21/05, Joost Kraaijeveld <J.Kraaijeveld@askesis.nl> 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
> = new_table_id)
> where new_table.id = 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 <http://www.askesis.nl;
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>



--
with regards,
S.Gnanavel
Satyam Computer Services Ltd.

view thread (9+ messages)  latest in thread

Message-ID: <eec3b03c0509210559253d2465@mail.gmail.com>
Permalink:  ../eec3b03c0509210559253d2465@mail.gmail.com/
Also on:    postgresql.org/message-id/eec3b03c0509210559253d2465@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: s.gnanavel@gmail.com, J.Kraaijeveld@askesis.nl
  Subject: Re: How to add column from old_table to new_table?
  In-Reply-To: <eec3b03c0509210559253d2465@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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