Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 444146338A3 for ; Thu, 16 Apr 2009 09:48:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 53953-08 for ; Thu, 16 Apr 2009 09:47:54 -0300 (ADT) X-Greylist: delayed 00:22:43.574432 by SQLgrey-1.7.6 Received: from a2s36.a2hosting.com (a2s36.a2hosting.com [74.126.18.130]) by mail.postgresql.org (Postfix) with ESMTP id 9BC89633275 for ; Thu, 16 Apr 2009 09:48:02 -0300 (ADT) Received: from adsl-70-108-249.tys.bellsouth.net ([98.70.108.249] helo=[192.168.1.16]) by a2s36.a2hosting.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1LuQea-0006MR-LZ; Thu, 16 Apr 2009 08:25:16 -0400 Cc: pgsql-sql@postgresql.org Message-Id: <5CDAA3CE-6B0F-4177-A5E1-241584EB6A90@pgedit.com> From: John DeSoi To: ShuA In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: Need a script that bakes INSERT script from SELECT results Date: Thu, 16 Apr 2009 08:25:15 -0400 References: X-Mailer: Apple Mail (2.930.3) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - a2s36.a2hosting.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pgedit.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/89 X-Sequence-Number: 32435 On Apr 16, 2009, at 7:29 AM, ShuA wrote: > Could someone post an example how to LOOP through row fields to wrap > them into 'VALUES(...,,)' list? If you declare record or table row types, you can insert the values using (rec.*), something like this: create or replace function test () returns void as $$ declare rec record; begin for rec in select * from whatever loop insert into some_table values (rec.*); end loop; end; $$ language plpgsql; John DeSoi, Ph.D.