0
A
回答
1
CREATE TABLE mytable(
id1 integer,
id2 integer
);
CREATE UNIQUE INDEX ON mytable(least(id1, id2), greatest(id1, id2));
这应该DDO的伎俩:
test=> INSERT INTO mytable VALUES (1, 2);
INSERT 0 1
test=> INSERT INTO mytable VALUES (1, 3);
INSERT 0 1
test=> INSERT INTO mytable VALUES (2, 1);
ERROR: duplicate key value violates unique constraint "mytable_least_greatest_idx"
DETAIL: Key ((LEAST(id1, id2)), (GREATEST(id1, id2)))=(1, 2) already exists.
相关问题
- 1. Postgresql约束
- 2. PostgreSQL检查约束
- 3. POSTGRESQL的约束条件
- 4. postgreSQL检查约束和空
- 5. PostgreSQL的约束问题
- 6. 约束表列名(postgresql)
- 7. 的PostgreSQL - 禁用约束
- 8. 由jdbc禁用postgresql约束
- 9. 用绳索约束连接网格
- 10. 连接约束去除余量
- 11. sql左外连接约束列
- 12. 装载机约束的java连接
- 13. 连接java与约束逻辑编程
- 14. 从连接中提取约束
- 15. 将PostgreSQL EXCLUDE范围约束与UNIQUE约束结合使用
- 16. Grails领域约束映射到PostgreSQL吉斯特约束
- 17. C#接口约束
- 18. PostgreSQL中的约束和断言
- 19. (PostgreSQL的)“高级”检查约束问题
- 20. postgresql外键约束,以防止重复
- 21. postgresql中的唯一约束问题
- 22. 约束排除随着PreparedStatments - PostgreSQL的
- 23. PostgreSQL的:默认的约束名
- 24. postgresql表约束不拒绝坏插入
- 25. PostgreSQL的UNIQUE约束和参考
- 26. PostgreSQL的使用约束前缀
- 27. 的PostgreSQL - 约束由触发器
- 28. PostgreSQL分区约束行为奇怪
- 29. Postgresql约束检查非ASCII字符
- 30. PDO没有约束力,PostgreSQL的查询
您运行的是什么版本.. –
我为使用PostgreSQL 9.6.2 – zlaayaa