I have a table mytable where is the 2 unique int field
# SQLAlchemy example
mytable = Table('mytable', meta,
# per-column anonymous unique constraint
Column('col1', Integer, unique=True),
Column('col2', Integer, unique=True),
# explicit/composite unique constraint. 'name' is optional.
UniqueConstraint('col1', 'col2', name='uix_1')
)
How to do restrictions like this:
col1 col2 1 2 6 3 1 4 5 5 6 1 -- FAIL: becouse 3-1 is exist and 2-6 is exist!!!
unique((col1, col2) union (col2, col1))
You can use something like this as a constraint:
If you want it to automatically make the col1 smaller than col2, use a trigger 🙂