PostgreSQL唯一性约束与排除约束

4

我有一个表格:

CREATE TABLE dbo."TransportInteraction"
(
  "Id" bigint NOT NULL DEFAULT nextval('dbo."TransportInteraction_Id_seq"'::regclass),
  "Message" character varying(256),
  "TransportActionId" integer NOT NULL,
  "TimeCreated" timestamp without time zone NOT NULL,
  "TimeInserted" timestamp without time zone NOT NULL,
  "TaskId" bigint
)

通常,此表映射任务上的操作。 TransportActionId 是一个整数,定义了操作类型。某些操作类型必须对于每个任务是唯一的,而其他一些则不需要。

因此,我需要一种类型的约束:
UNIQUE ("TaskId", "TransportActionId") 适用于所有具有 TransportActionId != (2||3 || 4) 的操作。

因此,除了那些 ActionId=2,3或4 的操作之外,所有操作都符合要求。

有什么想法吗?

1个回答

8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接