Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 68D8B63419E for ; Thu, 16 Apr 2009 08:54:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 17430-07 for ; Thu, 16 Apr 2009 08:54:00 -0300 (ADT) X-Greylist: delayed 00:10:38.951883 by SQLgrey-1.7.6 Received: from mx44.mail.ru (mx44.mail.ru [94.100.176.58]) by mail.postgresql.org (Postfix) with ESMTP id E309B632B5B for ; Thu, 16 Apr 2009 08:54:00 -0300 (ADT) Received: from f4.mail.ru (f4.mail.ru [194.67.57.65]) by mx44.mail.ru (mPOP.Fallback_MX) with ESMTP id 6F16D380002BB for ; Thu, 16 Apr 2009 15:29:46 +0400 (MSD) Received: from mail by f4.mail.ru with local id 1LuPmk-0008aN-00 for pgsql-sql@postgresql.org; Thu, 16 Apr 2009 15:29:38 +0400 Received: from [217.77.210.90] by win.mail.ru with HTTP; Thu, 16 Apr 2009 14:29:38 +0300 From: ShuA To: pgsql-sql@postgresql.org Subject: Need a script that bakes INSERT script from SELECT results Mime-Version: 1.0 X-Mailer: mPOP Web-Mail 2.19 X-Originating-IP: unknown via proxy [217.77.210.90] Date: Thu, 16 Apr 2009 14:29:38 +0300 X-Mru-Data: 2981:0:1:0:196:0 Reply-To: ShuA Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit Message-Id: X-Spam: Not detected X-Mras: Ok 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/88 X-Sequence-Number: 32434 I'm a novice to PL/pgSQL, and I'm curious, how to write function, that wraps SELECT results into INSERT script. The functionality I need is about to replicate table data into remote DB. I have tried dblink_build_insert(), but it requires primary key on tuple to create INSERT script from. I would prefer filter clause to primary key, to generate either multiple inserts or one multi-row insert. Could someone post an example how to LOOP through row fields to wrap them into 'VALUES(...,,)' list? Thanks, Olksy