Re: How to add column from old_table to new_table?

From: "A(dot) Kretschmer" <akretschmer(at)despammed(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to add column from old_table to new_table?
Date: 2005-09-21 12:56:25
Message-ID: 20050921125625.GB21483@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

am 21.09.2005, um 14:36:26 +0200 mailte Joost Kraaijeveld folgendes:
> Hi,
>
> I have an old_table with two columns: "id" and "old_attribute". I have
> new table with the columns "id" and "new_attribute".

There are indexes on id?

> Is that possible in a SQL script (pgadmin or psql console?) and if so,
> what is the syntax in this example?

Yes, of course.

>
> 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

Error, because i don't need a insert on new_table. You need a update!
(If there a primary index on id this will raise a error)

update t_new set name = (select name from t_old) where t_old.id=t_new.id;

(t_old and t_new are the tables with (id, name) similar your example)

Regards, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Pundt 2005-09-21 12:58:15 Re: How to add column from old_table to new_table?
Previous Message Joost Kraaijeveld 2005-09-21 12:50:55 Re: How to add column from old_table to new_table?