UPSERT in PostgreSQL using jOOQ

后端 未结 4 1812
死守一世寂寞
死守一世寂寞 2021-02-03 19:31

I am trying to perform an UPSERT in PostgreSQL using the jOOQ library.

For doing this I am currently trying to implement the following SQL statement in jOOQ: https://st

4条回答
  •  故里飘歌
    2021-02-03 19:46

    jOOQ 3.7+ supports PostgreSQL 9.5's ON CONFLICT clause:

    • https://github.com/jOOQ/jOOQ/issues/4299
    • http://www.postgresql.org/docs/9.5/static/sql-insert.html

    The full PostgreSQL vendor-specific syntax is not yet supported, but you can use the MySQL or H2 syntax, which can both be emulated using PostgreSQL's ON CONFLICT:

    MySQL INSERT .. ON DUPLICATE KEY UPDATE:

    DSL.using(configuration)
       .insertInto(TABLE)
       .columns(ID, A, B)
       .values(1, "a", "b")
       .onDuplicateKeyUpdate()
       .set(A, "a")
       .set(B, "b")
       .execute();
    

    H2 MERGE INTO ..

    DSL.using(configuration)
       .mergeInto(TABLE, A, B, C)
       .values(1, "a", "b")
       .execute();
    

提交回复
热议问题