X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1A29BD1B4A7 for ; Wed, 10 Mar 2004 20:49:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 56024-10 for ; Wed, 10 Mar 2004 16:49:36 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 39EA7D1B467 for ; Wed, 10 Mar 2004 16:49:34 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 013D43585C; Wed, 10 Mar 2004 12:49:34 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id F3F3F3585B; Wed, 10 Mar 2004 12:49:34 -0800 (PST) Date: Wed, 10 Mar 2004 12:49:34 -0800 (PST) From: Stephan Szabo To: Andreas Joseph Krogh Cc: pgsql-sql@postgresql.org Subject: Re: Inserting data in a table using sub-selects In-Reply-To: <200403102052.21825.andreak@officenet.no> Message-ID: <20040310124834.X36099@megazone.bigpanda.com> References: <200403102052.21825.andreak@officenet.no> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/116 X-Sequence-Number: 17215 On Wed, 10 Mar 2004, Andreas Joseph Krogh wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, I'd like to fill one table with the contents of another table. Mye schema > is like this: > > CREATE TABLE table1( > id serial NOT NULL PRIMARY KEY, > title varchar NOT NULL, > description varchar > ); > > CREATE TABLE table2( > id int NOT NULL REFERENCES(table1(id) ON DELETE CASCADE, > content varchar NOT NULL > ); > > Now - is there a way I can do something like: > INSERT INTO table2(id, content) values (select t1.id, coalesce(t1.title, '') > || ' ' || coalesce(t1.description, '') as content from table1 t1); I think you mostly just want to remove the values(): Insert into table2(id, content) select t1.id, coalesce(t1.title, '') || ' ' || coalesce(t1.description, '') as content from table t1;