Repository navigation
fix: honour ci_string in contains/2, string_starts_with/2, and string_ends_with/2 - #248
Merged
zachdaniel merged 1 commit intoOct 26, 2026
Conversation
Contributor
|
🚀 Thank you for your contribution! 🚀 |
Contributor
Author
|
Glad to help! 🚀 |
sfelixalejandro
deleted the
fix/ci-string-case-insensitive-substring-search
branch
October 26, 2026 03:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #228
Overview
In SQLite, collation sequences like
COLLATE NOCASEonly apply to comparison operators (=,!=,<,>,IN). Built-in scalar functions likeinstr(X, Y)completely ignore collations attached to their arguments. Additionally, becauseAshSqlite.Reposetscase_sensitive_like: :on,LIKEin SQLite is also case-sensitive and ignoresCOLLATE NOCASE.As reported in #228, queries using
containsorstring_starts_withagainst a%Ash.CiString{}or a resource attribute typed as:ci_stringwere compiled intoinstr(col, (? COLLATE NOCASE))orcol LIKE ?, failing to match case-insensitively.Solution
In
AshSqlite.SqlImplementation, we interceptContains,StringStartsWith, andStringEndsWith:ci_string(struct%Ash.CiString{}, attribute with storage type:ci_string, calculation, or typed expression):contains/2: compiles toinstr(LOWER(left), LOWER(right)) > 0string_starts_with/2: compiles toinstr(LOWER(left), LOWER(right)) = 1string_ends_with/2: compiles tolike(LOWER(left), escape_pattern)ci_string, it returns:errorand falls through toAshSql.Expr's default behaviour, preserving normal case-sensitive behavior without performance overhead.Tests
test/calculation_test.exsverifying case-insensitive matching forcontains,string_starts_with, andstring_ends_withusing both%Ash.CiString{}and:ci_stringresource attributes.