X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 161AB9DC9F0 for ; Thu, 29 Dec 2005 13:05:50 -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 57617-06 for ; Thu, 29 Dec 2005 13:05:48 -0400 (AST) X-Greylist: delayed 02:24:46.35502 by SQLgrey- Received: from lou-bada.torma.org (lou-bada.torma.org [213.41.177.64]) by postgresql.org (Postfix) with ESMTP id F22B19DC996 for ; Thu, 29 Dec 2005 13:05:47 -0400 (AST) Received: from lara.torma.org (lara.lou-bada.torma.org [10.7.3.65]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lou-bada.torma.org (Postfix) with ESMTP id 282235D5F8 for ; Thu, 29 Dec 2005 18:05:47 +0100 (CET) From: Teemu Torma To: pgsql-performance@postgresql.org Subject: Re: How import big amounts of data? User-Agent: KMail/1.9.1 References: <43B3B0EA.6070406@andromeiberica.com> <200512291541.05739.teemu@torma.org> <43B40C8F.6010100@andromeiberica.com> In-Reply-To: <43B40C8F.6010100@andromeiberica.com> MIME-Version: 1.0 Content-Disposition: inline X-Length: 1814 X-UID: 296 Date: Thu, 29 Dec 2005 18:05:45 +0100 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <200512291805.45684.teemu@torma.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200512/649 X-Sequence-Number: 16470 On Thursday 29 December 2005 17:19, Arnau wrote: > > - Use plpgsql function to do the actual insert (or update/insert if > > needed). > > > > - Inside a transaction, execute SELECT statements with maximum > > possible number of insert function calls in one go.  This minimizes > > the number of round trips between the client and the server. > > Thanks Teemu! could you paste an example of one of those functions? > ;-) An example of those SELECTS also would be great, I'm not sure I > have completly understood what you mean. An insert function like: CREATE OR REPLACE FUNCTION insert_values (the_value1 numeric, the_value2 numeric) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ BEGIN INSERT INTO values (value1, value2) VALUES (the_value1, the_value2); RETURN; END; $$; Then execute queries like SELECT insert_values(1,2), insert_values(2,3), insert_values(3,4); with maximum number of insert_values calls as possible. I think the transaction (BEGIN/COMMIT) has little time benefit if you have at least hundreds of calls in one SELECT. Teemu