Skip to content

Add case-insensitive unique constraints#1738

Merged
collerek merged 3 commits into
masterfrom
case-insensitive-unique-constraints
Jul 14, 2026
Merged

Add case-insensitive unique constraints#1738
collerek merged 3 commits into
masterfrom
case-insensitive-unique-constraints

Conversation

@collerek

Copy link
Copy Markdown
Collaborator

Adds IndexColumns(..., case_insensitive=True) to build a case-insensitive unique index by wrapping each named column in LOWER(), so values differing only in case cannot both be stored. IndexColumns now also accepts SQLAlchemy expressions for arbitrary functional indexes, and index auto-naming derives names from the index expressions so functional indexes get valid names. On MySQL this needs 8.0.13+.

Closes #615

Add IndexColumns(case_insensitive=True) to build a case-insensitive
unique index by wrapping each named column in LOWER(). IndexColumns now
also accepts SQLAlchemy expressions for arbitrary functional indexes,
and index auto-naming derives names from the index expressions so
functional indexes get valid names.

Closes #615
@codspeed-hq

codspeed-hq Bot commented Jul 13, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 21.35%

⚡ 1 improved benchmark
✅ 97 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_update_or_create_when_create[20] 165.7 ms 136.5 ms +21.35%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing case-insensitive-unique-constraints (28c5053) with master (6fafb9f)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (568f4da) during the generation of this report, so 6fafb9f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

collerek added 2 commits July 14, 2026 09:39
Add a runtime test that a raw SQLAlchemy expression functional unique
index (UPPER(name)) enforces case-insensitive uniqueness, and switch the
standalone-expression example from LOWER to UPPER in docs and test so it
is distinct from the built-in case_insensitive=True path.
@collerek
collerek merged commit e910772 into master Jul 14, 2026
11 checks passed
@collerek
collerek deleted the case-insensitive-unique-constraints branch July 14, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Case insensitive unique constraints

1 participant