Re: multiple data to insert to database
| From: | Robert Cummings | Date: | Fri, 10 Aug 2007 13:50:59 +0000 |
| Subject: | Re: multiple data to insert to database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-260572@lists.php.net to get a copy of this message | ||
On Fri, 2007-08-10 at 15:36 +0200, Alain Roger wrote:
> Hi,
>
> I would like to know what is the best way and fastest to insert into
> PostgreSQL around 25.000 records (extracted from CSV file).
> Should i use the standard pg_exec($dbconn, "insert into..."); for each
> record ?
>
> thanks a lot,
Let's say you have a table with an id and a value field. Where id is the
key. You should be able to stack inserts like follows:
INSERT INTO foo ( id, value ) VALUES ( 1, 'One' ), ( 2, 'Two' ), ( 3,
'threee' );
So with that in mind, you should cluster your inserts into groups of X
inserts. I few hundred should make things a little quicker for you.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................