jooq-识别postgres UNIQUE约束的问题

问题描述 投票:1回答:1

正在尝试:

context.insertInto(table(ERROR_TABLE))
  .set(valuesMap)
  .onConflictOnConstraint(constraint(name("push_def_rec_error_idx"))
  .doUpdate()
  .set(field(name(fieldname)), value)
  .execute();

告诉我一个错误:

错误:表“ push_error”的约束“ push_def_rec_error_idx”不存在

表定义(通过\d+ table_name):

...

Indexes:
    "push_record_error_pkey" PRIMARY KEY, btree (push_record_error_id)
    "push_def_rec_error_idx" UNIQUE, btree (push_definition_id, rec_id)

我在做什么错?

这是用于SQLDialect.POSTGRES_10

postgresql jooq
1个回答
0
投票

您命名索引的方式,我假设您对这些列没有约束,但UNIQUE INDEX

CREATE TABLE T (a INT PRIMARY KEY, b INT, c INT);
CREATE UNIQUE INDEX u ON t(b);

INSERT INTO T (a, b, c)
VALUES (1, 2, 3)
ON CONFLICT ON CONSTRAINT u
DO UPDATE SET c = 4
RETURNING *;

以上产生:

[42704]: ERROR: constraint "u" for table "t" does not exist

但是,将索引变成约束:

DROP INDEX u;
ALTER TABLE t ADD CONSTRAINT u UNIQUE (b);

[INSERT语句现在可以使用。

See an explanation here about the difference between unique constraints and unique indexes

© www.soinside.com 2019 - 2024. All rights reserved.