From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: Inserting data in a table using sub-selects
Date: Wed, 10 Mar 2004 12:49:34 -0800 (PST)
Message-ID: <20040310124834.X36099@megazone.bigpanda.com> (raw)
In-Reply-To: <200403102052.21825.andreak@officenet.no>
References: <200403102052.21825.andreak@officenet.no>
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;
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: sszabo@megazone.bigpanda.com, andreak@officenet.no
Subject: Re: Inserting data in a table using sub-selects
In-Reply-To: <20040310124834.X36099@megazone.bigpanda.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