Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 98CFC476911 for ; Fri, 5 Jul 2002 08:45:25 -0400 (EDT) Mailbox-Line: From mkoi-pg@aon.at Fri Jul 5 08:45:25 2002 Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 1F180476905 for ; Fri, 5 Jul 2002 08:41:24 -0400 (EDT) Received: by news.hub.org (Postfix, from userid 8) id 12033381D1F; Fri, 5 Jul 2002 08:40:50 -0400 (EDT) From: Manfred Koizar X-Newsgroups: comp.databases.postgresql.sql Subject: Re: sql statement how to do ? Date: Fri, 05 Jul 2002 14:40:10 +0200 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 29 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: news@hub.org X-Newsreader: Forte Agent 1.8/32.548 To: pgsql-sql@postgresql.org X-Spam-Status: No, hits=-0.1 required=5.0 tests=SUBJ_ENDS_IN_Q_MARK version=2.30 X-Spam-Level: X-Archive-Number: 200207/61 X-Sequence-Number: 8440 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