小编tad*_*eas的帖子

Postgresql强制执行唯一的双向组合列

我正在尝试创建一个表,该表将强制执行两个相同类型的两个列的唯一组合 - 在两个方向上.例如,这将是非法的:

col1 col2
   1    2
   2    1
Run Code Online (Sandbox Code Playgroud)

我想出了这个,但它不起作用:

database=> \d+ friend;
                                Table "public.friend"
    Column    |           Type           | Modifiers | Storage  | Stats target | Description
--------------+--------------------------+-----------+----------+--------------+-------------
 user_id_from | text                     | not null  | extended |              |
 user_id_to   | text                     | not null  | extended |              |
 status       | text                     | not null  | extended |              |
 sent         | timestamp with time zone | not null  | plain    |              |
 updated      | timestamp with time zone |           | plain …
Run Code Online (Sandbox Code Playgroud)

postgresql combinations unique

5
推荐指数
2
解决办法
918
查看次数

标签 统计

combinations ×1

postgresql ×1

unique ×1