X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3EA53475843 for ; Mon, 3 Mar 2003 12:52:45 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 67160-04 for ; Mon, 3 Mar 2003 12:52:43 -0500 (EST) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by postgresql.org (Postfix) with ESMTP id 4D8F3474E61 for ; Mon, 3 Mar 2003 12:52:43 -0500 (EST) Received: from lfix.demon.co.uk ([158.152.59.127] helo=linda.lfix.co.uk) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 18pu7L-0003LP-0Z; Mon, 03 Mar 2003 17:52:48 +0000 Received: from localhost ([127.0.0.1] ident=olly) by linda.lfix.co.uk with esmtp (Exim 3.36 #1 (Debian)) id 18pu7F-00045k-00; Mon, 03 Mar 2003 17:52:41 +0000 Subject: Re: Insert multiple Rows From: Oliver Elphick To: Saint X Cc: pgsql-sql@postgresql.org In-Reply-To: <6f079210.0303030838.21f184af@posting.google.com> References: <6f079210.0303030838.21f184af@posting.google.com> Content-Type: text/plain Organization: LFIX Limited Message-Id: <1046713959.2173.144.camel@linda.lfix.co.uk> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 03 Mar 2003 17:52:41 +0000 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/82 X-Sequence-Number: 12122 On Mon, 2003-03-03 at 16:38, Saint X wrote: > Hi, I have a program that need to send a Postgresql database a lot of > rows, i'm doing it using FOR an INSERT, something like this > for i = 0 to 1000 > { > insert into table(item1) VALUES (i); > } > > And so on, as you can imagine these consume a lot of resources and > move so slowly, that's why I'm looking for a command to send more than > one row at the time, something like > > insert into table (item1) values ('1' / '2' / '3' / '4' ... / '1000'); Have you started a transaction first? If not, every INSERT will be a separate transaction, which will take much longer. Do: BEGIN INSERT ... INSERT ... ... many times ... COMMIT > The data I want to send come from variables on the program, coping > local variables is fast so i can make my query on a variable with all > the data and then send just one query to the database. > > I was looking on PostgreSQL documentation and find nothing,, I think > that what I'm looking for doesn't exist,, you are my last resource, it > possible to do what I want? > > BTW: I found a command on Postgre to pass a file with all the info but > the database is not on local machine and its a little hard to send it > a file. Using COPY will be even faster. To send a file from the remote system, run psql on the remote system and use \copy rather than COPY. -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "A new commandment I give to you, that you love one another, even as I have loved you." John 13:34