X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CFFCB9DCA19 for ; Wed, 15 Mar 2006 04:35:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49448-04 for ; Wed, 15 Mar 2006 04:35:44 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 1F7F49DC9DF for ; Wed, 15 Mar 2006 04:35:42 -0400 (AST) Received: from smtp20.kymp.net (smtp20.kymp.net [80.248.96.137]) by svr4.postgresql.org (Postfix) with ESMTP id 4A1285AF852 for ; Wed, 15 Mar 2006 08:35:36 +0000 (GMT) Received: from [192.168.0.100] (static-241-66.kymp.net [213.130.241.66]) by smtp20.kymp.net (8.13.3/8.13.3) with SMTP id k2F8ZRtw004298 for ; Wed, 15 Mar 2006 10:35:28 +0200 From: Aarni =?iso-8859-1?q?Ruuhim=E4ki?= Reply-To: aarni@kymi.com To: pgsql-sql@postgresql.org Subject: Re: Copying a row within table Date: Wed, 15 Mar 2006 10:35:27 +0200 User-Agent: KMail/1.6.2 References: <200603140919.49246.aarni@kymi.com> In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Organization: KYMI.com Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200603151035.27261.aarni@kymi.com> X-Virus-Scanned: by amavisd-new X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.181 required=5 tests=[AWL=0.181] X-Spam-Score: 0.181 X-Spam-Level: X-Archive-Number: 200603/226 X-Sequence-Number: 24572 On Wednesday 15 March 2006 03:11, John DeSoi wrote: > On Mar 14, 2006, at 2:19 AM, Aarni Ruuhim=E4ki wrote: > > testing=3D# INSERT INTO foo (foo_1, foo_2, foo_3 ...) (SELECT foo_1, > > foo_2, > > foo_3 ... FROM message_table WHERE foo_id =3D 10); > > INSERT 717286 1 > > testing=3D# > > > > Is there a fast way to copy all but not the PK column to a new row > > within the > > same table so that the new foo_id gets its value from the sequence ? > > Here is an example using a plpgsql function: > > create or replace function test_duplicate (p_id integer) > returns integer as $$ > declare > tt test%rowtype; > begin > select into tt * from test where id =3D p_id; > tt.id :=3D nextval(pg_get_serial_sequence('test', 'id')); > insert into test values (tt.*); > return tt.id; > end; > $$ language plpgsql; > > > > > > > John DeSoi, Ph.D. > http://pgedit.com/ > Power Tools for PostgreSQL > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org Hi, Thank you guys, I'll try these. Reason I need this is I have a largish product table which stores slightly= =20 different types of products and for some types it is extremely handy to jus= t=20 clone an existing product and then change the name and other few details=20 rather than go the time consuming way of creating a new almost identical=20 product from scratch filling in all the required values and calling all the= ir=20 check routines in the application. Different types do not use all or the sa= me=20 colums, some are left null or empty and some have different boolean values = in=20 one or more columns. Best regards and thanks again, Aarni =2D------------- This is a bugfree broadcast to you from **Kmail** on **Fedora Core** linux system =2D-------------