UPSERT in PostgreSQL using jOOQ

后端 未结 4 1799
死守一世寂寞
死守一世寂寞 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 20:01

    Here is an upsert utility method derived from Lucas' solution above for UpdatableRecord objects:

    public static int upsert(final DSLContext dslContext, final UpdatableRecord record) {
        return dslContext.insertInto(record.getTable())
                         .set(record)
                         .onDuplicateKeyUpdate()
                         .set(record)
                         .execute();
    }
    

提交回复
热议问题