Postgresql enforce unique two-way combination of columns
问题 I'm trying to create a table that would enforce a unique combination of two columns of the same type - in both directions. E.g. this would be illegal: col1 col2 1 2 2 1 I have come up with this, but it doesn't work: 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 |