I am using SQLAlchemy and PostgreSQL, and I am trying to create a case-insensitive unique constraint that works like this UniqueConstraint( 'country', 'organisation_id', func.lower(func.trim('name')), name='uq_country_orgid_lower_trim_name' ) Ensuring a unique combination of name, country and organisation id, regardless of case and spacing in the name, i.e. "Name 1", "name1", "nAmE 1" would all be handled as "name1" in the check. I want to make sure that I do not change the actual case or spacing of the name saved in the database. How would I go about this? Continue reading...