zio / zio-protoquill

Quill for Scala 3
Apache License 2.0
198 stars 48 forks source link

Batch insert with empty collection generates invalid SQL #431

Open vladimir-lu opened 3 months ago

vladimir-lu commented 3 months ago

Version: 4.8.3 Module: quill-jdbc Database: postgres

Actual behavior

When doing ctx.run(liftQuery(values).foreach(v => valueSchema.insert(v))) with a collection that is empty, the following SQL is generated: INSERT INTO table (a, b, c, ...) VALUES. The trailing VALUES is not parseable by postgres + sqlite (and probably others).

Expected behavior

Should be able to insert an empty collection of values (it should probably be a noop on the dynamic batcher level).

Steps to reproduce the behavior

Modify BatchUpdateValuesSpec to have an empty list for val dataBase: List[ContactBase] = Nil

Workaround

Check whether collection is empty before calling insert.

@getquill/maintainers