From: Manfred Koizar <mkoi-pg@aon.at>
To: pgsql-sql@postgresql.org
Subject: Re: sql statement how to do ?
Date: Fri, 05 Jul 2002 14:40:10 +0200
Message-ID: <v34biu447apt49qoru6ib7r1quifes4526@4ax.com> (raw)
References: <OFE12270DD.E9422A84-ONC1256BED.00312C52-C1256BED.0031B2A6@pup.ch>
On Fri, 5 Jul 2002 09:03:38 +0000 (UTC), juerg.rietmann@pup.ch wrote:
>INSERT INTO auftrag (SELECT * FROM auftrag where a_id = '12345');
>
>The problem is, that the table auftrag has a primay key called pk_auftrag.
>Do this I get an error regarding duplicate pk_auftrag. Is there a way to
>spare pk_auftrag somehow ?
Juerg, is a_id your primary key? My examples are based on this
assumption, but if it is not, you still get the point, which is:
You can't use SELECT * here.
If you know the new a_id in advance:
INSERT INTO auftrag (a_id, col2, col3, ...)
SELECT '67890', col2, col3, ...
FROM auftrag
WHERE a_id = '12345';
If a_id is a serial or in any other way supplied automatically by a
DEFAULT clause or a trigger:
INSERT INTO auftrag (col2, col3, ...)
SELECT col2, col3, ...
FROM auftrag
WHERE a_id = '12345';
HTH.
Servus
Manfred
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: mkoi-pg@aon.at
Subject: Re: sql statement how to do ?
In-Reply-To: <v34biu447apt49qoru6ib7r1quifes4526@4ax.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