sqlite-simple icon indicating copy to clipboard operation
sqlite-simple copied to clipboard

INSERTs with executeMany should only emit one INSERT query

Open jdreaver opened this issue 5 years ago • 1 comments

Hello!

I noticed today that when I INSERT with executeMany, there are multiple insert queries instead of a single query. SQLite supports lists of values to insert mutliple rows in a single query. For example:

> create table test (a integer, b integer);
> insert into test (a, b) values (1, 2), (3, 4);
> select * from test;
a           b         
----------  ----------
1           2         
3           4 

executeMany does this:

> insert into test (a, b) values (1, 2);
> insert into test (a, b) values (3, 4);

which of course is less efficient than doing it all in one query.

postgresql-simple seems to know about this, so I was surprised to see sqlite-simple emit multiple insert queries.

jdreaver avatar Jan 28 '20 17:01 jdreaver

Hi, yes insertMany is a for loop https://github.com/nurpax/sqlite-simple/blob/7ff345f8ed48238a7eb085ecf951f5a994575f95/Database/SQLite/Simple.hs#L324 of simple queries. This will probably improved over next couple releases.

sigrlami avatar Jan 28 '20 17:01 sigrlami