Knex(postres) - 有没有办法让一列只在某些情况下是唯一的
Knex(postres) - Is there a way to have a column unique only on some instances
我有一个 table,它有 3 列(id、名称、orgId(外键)
我想要实现的是,如果只有 orgId 匹配
,则列名是唯一的
如何定义模式?
这将是在两列上定义的唯一约束:
ALTER TABLE tab ADD UNIQUE (orgid, name);
这将仅排除 name
和 orgid
与现有行相同的行。
我有一个 table,它有 3 列(id、名称、orgId(外键) 我想要实现的是,如果只有 orgId 匹配
,则列名是唯一的如何定义模式?
这将是在两列上定义的唯一约束:
ALTER TABLE tab ADD UNIQUE (orgid, name);
这将仅排除 name
和 orgid
与现有行相同的行。