Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 5F1B69FB40F for ; Fri, 8 Jun 2007 07:55:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 62025-05 for ; Fri, 8 Jun 2007 07:55:26 -0300 (ADT) X-Greylist: delayed 00:20:43.199257 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id B63099FB425 for ; Fri, 8 Jun 2007 07:55:32 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from alsikeapila.uta.fi (alsikeapila.uta.fi [153.1.1.44]) by svr4.postgresql.org (Postfix) with ESMTP id 42EA95AF87E for ; Fri, 8 Jun 2007 10:34:46 +0000 (GMT) Received: from valkoapila.uta.fi (valkoapila.uta.fi [153.1.1.42]) by alsikeapila.uta.fi (8.13.8/8.13.8) with ESMTP id l58AYfl4025936 for ; Fri, 8 Jun 2007 13:34:41 +0300 (EEST) Received: from apila.uta.fi (localhost.localdomain [127.0.0.1]) by valkoapila.uta.fi (8.13.8/8.13.8) with ESMTP id l58AYeQg007537 for ; Fri, 8 Jun 2007 13:34:40 +0300 Received: from piippo.uta.fi (piippo.uta.fi [153.1.6.43]) by apila.uta.fi (8.13.8/8.13.8) with ESMTP id l58AYerR023704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 8 Jun 2007 13:34:40 +0300 (EEST) Received: from piippo.uta.fi (localhost.localdomain [127.0.0.1]) by piippo.uta.fi (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id l58AYeoH017576 for ; Fri, 8 Jun 2007 13:34:40 +0300 Received: (from wwwroot@localhost) by piippo.uta.fi (8.13.4/8.13.4/Submit) id l58AYeeN017575 for pgsql-php@postgresql.org; Fri, 8 Jun 2007 13:34:40 +0300 Received: from kielitranpc59.uta.fi (kielitranpc59.uta.fi [153.1.35.59]) by imp1.uta.fi (Horde MIME library) with HTTP; Fri, 08 Jun 2007 13:34:40 +0300 Message-ID: <20070608133440.tiz9hbu3y9s0k8oo@imp1.uta.fi> Date: Fri, 08 Jun 2007 13:34:40 +0300 From: Mihail Mihailov To: pgsql-php@postgresql.org Subject: Re: [newbie] How to do "batch insert"? References: <466916DA.2080903@gmail.com> In-Reply-To: <466916DA.2080903@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Internet Messaging Program (IMP) H3 (4.1.5-cvs) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (apila.uta.fi [153.1.1.41]); Fri, 08 Jun 2007 13:34:40 +0300 (EEST) X-Scanned-By: MIMEDefang 2.62 on 153.1.1.42 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/2 X-Sequence-Number: 3804 Hi Ian, It should be much easier to use pg_query function. pg_query("START TRANSACTION"); for (......) { $your_insert_query =3D "INSERT INTO acls(oid,uid,gid,mod) =20 VALUES($1,$2,$3,$4)" $r =3D pg_query($your_insert_query); if (!$r) //Query failed { //issue error message // exit loop, all changes in the table will not be saved } } pg_query("COMMIT"); //Commit all changes in the table If you mark the transaction block ("start transaction" ... "commit") =20 the changes will be commited only after the script reaches "commit" =20 clause. If it is aborted before, no changes will be saved. This is the =20 purpose of transaction (which is also the way to increase the speed of =20 the program execution). - Mike Quoting =E6=9D=8E=E5=BD=A6 Ian Li : > Hi all. > In the scene I want to insert all elements of an array in to a table, > how can I do to commit them as a whole? > currently I do like this: > > $result =3D pg_prepare($dbconn, "ins_acl", 'INSERT INTO > acls(oid,uid,gid,mod) VALUES($1,$2,$3,$4)'); > for($i=3D0;$i =09pg_execute($dbconn, "ins_lgs",$p["acls"][i]); > } > ?> > > I wonder while doing so, will it commit in each LOOP or just ONCE? > > Thanks and Regards, > > Ian > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq