[JDBC] reWriteBatchedInserts=true not working with ON CONFLICT DO UPDATE - Mailing list pgsql-jdbc

From Thomas Kellerer
Subject [JDBC] reWriteBatchedInserts=true not working with ON CONFLICT DO UPDATE
Date
Msg-id ob2isj$n2o$1@blaine.gmane.org
Whole thread Raw
List pgsql-jdbc
When using the new reWriteBatchedInserts=true feature, this fails when using ON CONFLICT DO UPDATE ...

Assume the following table:

   create table testbatch (x integer primary key, y integer)

And the following code:

    pstmt = con.prepareStatement("insert into testbatch (x, y) values (?,?) on conflict (x) do update set y =
exluded.y");
    pstmt.setInt(1,1);
    pstmt.setInt(2,1);
    pstmt.addBatch();

    pstmt.setInt(1,2);
    pstmt.setInt(2,2);
    pstmt.addBatch();

    pstmt.executeBatch();

The executeBatch() fails with:

java.sql.BatchUpdateException: Batch entry 0

   insert into testbatch (x, y) values (1,1) on conflict (x),(2,2) on conflict (x) do update set y = exluded.y was
aborted:ERROR: syntax error at or near "," 

It seems the rewrite code doesn't take the on conflict clause into account properly.

However, it _does_ work correctly with ON CONFLICT DO NOTHING

Tested with postgresql-42.0.0.jar

Regards
Thomas





pgsql-jdbc by date:

Previous
From: Daniel Migowski
Date:
Subject: [JDBC] [pgjdbc/pgjdbc] a7e0c8: feat: improve waiting for notifications byprovidi...
Next
From: Dave Cramer
Date:
Subject: Re: Interest in allowing caller to push binary data ratherthan having it pulled?