# Batched insert queries, passing in multiple rows as params

**URL:** <https://dev.lucee.org/t/batched-insert-queries-passing-in-multiple-rows-as-params/15274>\
**Category:** proposals\
**Created:** [July 15, 2025, 2:18pm UTC](https://dev.lucee.org/t/batched-insert-queries-passing-in-multiple-rows-as-params/15274 "2025-07-15T14:18:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zackster](https://dev.lucee.org/user_avatar/dev.lucee.org/zackster/32/3484_2.png) [@Zackster](https://dev.lucee.org/u/Zackster)\
**Post date:** [July 15, 2025, 2:18pm UTC](https://dev.lucee.org/t/batched-insert-queries-passing-in-multiple-rows-as-params/15274/1 "2025-07-15T14:18:35Z")

</div>

After looking into this problem a few weeks ago, it got me thinking

> [@Query each slow (Lucee 6.2.)](https://dev.lucee.org/t/query-each-slow-lucee-6-2/15241):
>
> I upgraded my local stack to lucee 6.2.2 / jdk 21 / tomcat 11. I have a small script, uploading a csv file (6 columns), parse each data field (e.g. validate) and then i collect the rows in an array. If the array length is 100, I create one “INSERT INTO” sql statement with 100 rows. The file has 363 rows, really nothing special and this works within less seconds. After the upgrade, the script ran in a timeout and the Query each-function is terrible slow: The Lucee web admin al…

this was using the approach of multiple values with an insert

```auto
insert into tbl (id) values (?) ,(?), (?).....etc

```

At the moment it’s either that approach or looping over an insert statement, but that’s not great performance wise even within a transaction.

For the multi-table QoQ, we load all the queries using jdbc into a temp database for we can execute them

> <https://github.com/lucee/Lucee/blob/7.0/core/src/main/java/lucee/runtime/db/HSQLDBHandler.java#L156>

My idea was to allow passing in multiple rows into cfquery and then efficiently inserting them once, avoiding going thru all the query processing code for each row, or using massive value statements like above

I’ve started on a proof of concept PR for this with `<CFQUERY>`

```auto
cfquery( sql=insertSql, params=arr, datasource=ds, batch=true );

```

> <https://github.com/lucee/Lucee/pull/2620>
>
> https://luceeserver.atlassian.net/browse/LDEV-5704

[https://luceeserver.atlassian.net/browse/LDEV-5704](https://luceeserver.atlassian.net/browse/LDEV-5704)

It’s a bit hacky and needs more refactoring but the initial results are quite promising for high performance inserts (i.e it can go even much faster)

```auto
 [java] [script] test.tickets.LDEV5704
 [java] [script] individual took 287ms for 1000 rows
 [java] [script] individual (w/transaction) took 188ms for 1000 rows
 [java] [script] batch took 45ms for 1000 rows

```

I wouldn’t mind being able to potentially supporting passing in a `query` as `params` and have Lucee automatically read the query metadata and handle all the `sqltypes` etc (which I’m manually doing in the testcase for now)
