Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnConflictIgnore does not work with batch insert on H2 #298

Closed
pragmaxim opened this issue Jul 9, 2023 · 1 comment
Closed

OnConflictIgnore does not work with batch insert on H2 #298

pragmaxim opened this issue Jul 9, 2023 · 1 comment

Comments

@pragmaxim
Copy link

pragmaxim commented Jul 9, 2023

Version: 4.6.0.1
Module: quill-sql
Database: h2 2.1.214

Actual behavior

Having : url="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH;INIT=RUNSCRIPT FROM 'classpath:h2-schema.sql'"

Upsert is supported by Postgres, SQLite, MySQL and H2 onConflictIgnore only (since v1.4.200 in PostgreSQL compatibility mode)

While using h2 datasource and table :

create table if not exists ErgoTree (
    hash            VARCHAR(64) NOT NULL PRIMARY KEY,
    blockId         VARCHAR(64) NOT NULL REFERENCES Block (blockId) ON DELETE CASCADE,
    hex             VARCHAR NOT NULL
);
quote {
  liftQuery(ergoTrees).foreach(ergoTree => query[ErgoTree].insertValue(ergoTree).onConflictIgnore)
}
zio.FiberFailure: Malformed batch entity: Foreach(                                                                     
  ScalarTag("478a148e-9ea3-4726-ba2b-8146a2a24cb5", Parser),
  Id("ergoTree"),                                                                                                                                                                                                                              
  OnConflict(                        
    Insert(                                                                                                            
      Entity("ErgoTree", List()),                          
      List(                                                                                                            
        Assignment(Id("_$V"), _$V.hash, ergoTree.hash),                                                                
        Assignment(Id("_$V"), _$V.blockId, ergoTree.blockId),                                                          
        Assignment(Id("_$V"), _$V.hex, ergoTree.hex)      
      )                                 
    ),
    NoTarget,
    Ignore
  )
). Batch insertion entities must have the form Insert(Entity, Nil: List[Assignment])
        at io.getquill.context.QueryExecutionBatchDynamic$.rightOrException(QueryExecutionBatchDynamic.scala:183)
        at io.getquill.context.QueryExecutionBatchDynamic$.extractPrimaryComponents(QueryExecutionBatchDynamic.scala:220)
        at io.getquill.context.QueryExecutionBatchDynamic$.apply(QueryExecutionBatchDynamic.scala:120)
        at org.ergoplatform.uexplorer.backend.boxes.PersistentBoxRepo.insertUtxos(PersistentBoxRepo.scala:42)
        at org.ergoplatform.uexplorer.backend.boxes.BoxRepo$.insertUtxos$$anonfun$1(BoxRepo.scala:36)
        at zio.ZIO$ServiceWithZIOPartiallyApplied$.apply$extension$$anonfun$13$$anonfun$1(ZIO.scala:5332)
        at org.ergoplatform.uexplorer.backend.boxes.BoxRepo.insertUtxos(BoxRepo.scala:36)
        at org.ergoplatform.uexplorer.backend.H2Backend.blockWriteFlow(H2Backend.scala:58)
        at org.ergoplatform.uexplorer.backend.H2Backend.blockWriteFlow(H2Backend.scala:61)
        at org.ergoplatform.uexplorer.backend.H2Backend.blockWriteFlow(H2Backend.scala:62)
onConflictIgnore(_.hash)

does the same error and

liftQuery(ergoTrees).foreach(ergoTree =>
  query[ErgoTree].insert(_.hex -> ergoTree.hex, _.blockId -> ergoTree.blockId).onConflictIgnore(_.hash)
)

too, onIgnoreUpdate has the same issue. Simple insert works, this is only an issue of batch insert.

@pragmaxim pragmaxim changed the title OnConflictIgnore does not work with batch insert OnConflictIgnore does not work with batch insert on H2 Jul 9, 2023
@pragmaxim
Copy link
Author

#250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant