Re: [Q] PDO use to bind arrays for insert

From: "V S P" <toreason(at)fastmail(dot)fm>
To: knl(at)bitflop(dot)com
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: [Q] PDO use to bind arrays for insert
Date: 2008-11-17 03:01:13
Message-ID: 1226890873.32288.1285117971@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Hi Kim,
thank you for the reply
Yes, I thought I can use prepared statements to optimize
the insert speed.

I was just looking for a further optimization
(because prepared inserts still cause a network trip
for every insert (but SQL is not parsed everytime because
it is prepared))

In otherwords what I wanted (conseptually is)

insert into work_items (work_id, work_desc) values
(:bound_ar_of_work_ids, :bound_ar_of_work_desc)

bindParameter(":bound_ar_of_work_ids", ar_of_work_ids, PDO::ARRAY_INT);

bindParameter(":bound_ar_of_work_desc",ar_of_work_desc,PDO::ARRAY_STRING);

I understand that I could simply generate the
string such as

insert into work_items (work_id, work_desc)
values (
("id_val1", "desc_val1"),
("id_val2", "desc_val2"),
("id_val3","desc_val3")
...
);

But the problem with the above that it will not be prepared
-- so the SQL engine will be parsing it
(also some SQL engines besides parsing, may assign a
Optimizer plan to prepared queries, not sure if PG does that)

I think Chris @ dmagick pointed to a raw string functionality
that -- so I will need to figure out if
a) it actually saves on parsing
b) if it will work with PG connection pooling (which I am not
using yet, but will in the future).

> $stmt->bindParam (':work_desc', $work_desc, PDO::PARAM_STR);
>
> for ($i = 0; $i < count($my_array); $i++) {
>
> $work_desc = $my_array[$i];
>
> $stmt->execute();
>
> }
>
> Kim Lesmer
--
V S P
toreason(at)fastmail(dot)fm

--
http://www.fastmail.fm - The professional email service

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Andrew McMillan 2008-11-17 04:05:47 Re: [Q] PDO use to bind arrays for insert
Previous Message Chris 2008-11-16 21:41:57 Re: [Q] PDO use to bind arrays for insert