Hi,
On Wednesday 21 September 2005 14:36, Joost Kraaijeveld wrote:
| Is that possible in a SQL script (pgadmin or psql console?) and if so,
| what is the syntax in this example?
funny that you mention pgadmin :-)
| 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
from the pgadmin help system (reference|sql commands|insert):
INSERT INTO table [ ( column [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query }
and some lines further an example:
This example inserts some rows into table films from a table tmp_films with the same column layout as films:
INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2004-05-07';
Or - if I was misunderstanding your question and you simply want to update
already existing rows in "new_table", you might try
UPDATE new_table SET new_attribute = old_table.old_attribute FROM old_table WHERE new_table.id =
old_table.id;
Ciao,
Thomas
--
Thomas Pundt <thomas.pundt@rp-online.de> ---- http://rp-online.de/ ----