Skip to content
WebsiteHosting.com

concept Data & storage

Database collations and case-sensitive comparisons

The collation determines how text compares. In SQLite, `A` sorts before `a` under BINARY but ties with it under built-in NOCASE. That tie matters when a unique index uses the same rule.

Latest recorded source check · P0246

What it means

A collation is the rule a database uses to compare text. Change the rule, and two strings can go from sorting one before the other to tying, without either string changing. SQLite’s collation rules

Consider A and a as nonnull SQLite TEXT values. BINARY compares their bytes. SQLite’s built-in NOCASE folds ASCII A–Z to a–z for comparison; it is not a case-folding rule for all languages. SQLite built-in collations

Try it

Start with A as the Existing text value and a as the Candidate text value. For the uniqueness question, suppose a single-column unique index contains just the existing value and uses the selected collation. A candidate that compares equal under that index’s rule conflicts with the existing entry. SQLite unique indexes and collations

Database collations and case-sensitive comparisons

Choose among a few sourced, explicit collation examples; show equality, ordering and uniqueness consequences with unknown for unsupported locale rules.

Simulation

Synthetic inputs only. This is not a measurement of your hardware or service.

Computed under the stated assumptions

The selected built-in collation determines text comparison. The unique-conflict example stipulates one existing nonnull TEXT value and a unique index using this same collation.

Database collations and case-sensitive comparisons: synthetic scenario inputs

Scenario: Starting example

Each preset replaces all fields. Editing any field preserves the other values exactly, including invalid entries.

Text → comparison keys → equality and order

Existing, then candidate comparison key
A · a
Compare equal
No
Existing value relative to candidate
before
Conflict in the stipulated unique index
No

Evaluated evidence

Named SQLite text collation
SQLite3-BINARY
Existing text value
A
Candidate text value
a
SQLite storage class
TEXT
Text encoding
UTF-8

No Unicode-wide lowercase approximation, custom collation, type affinity, NULL, RTRIM or actual database execution. Equal sort keys do not establish a stable order between separate rows.

About this model

Every input is local synthetic evidence. Numbers stay as raw text until this model validates them. The shown evaluated values come from the same result as the explanation.

Presets replace the entire scenario. Reset restores all starting fields, scenario selection and model state; it does not change the open or closed state of this help or article FAQ.

No external request, device command, stored-input history or measurement is performed.

  1. With Named SQLite text collation set to SQLite3-BINARY, the comparison keys are A and a. In UTF-8 their bytes are 65 and 97, respectively. The existing value sorts before the candidate, the two are not equal, and there is no conflict in this index.
  2. Choose Use SQLite ASCII NOCASE. The inputs are still A and a, but the comparison keys are now a and a. Neither sorts before the other: they compare equal, so the candidate would conflict. For sorting alone, a tie does not determine which of two separate rows comes first.
  3. Choose Inspect the evidence boundary to compare é and É under SQLite3-NOCASE. The simulation returns unknown, not “unequal”: the pair is outside its printable-ASCII domain. It predicts neither an order nor a uniqueness outcome.

The simulation does not query a database. Reset restores the original profile and both text values and clears prior comparisons, history, and errors.

In practice

To specify uniqueness for a list of printable-ASCII labels, say whether a change of letter case alone is allowed to distinguish two labels. For A and a, a BINARY unique index allows both; a built-in NOCASE unique index does not. Name the index’s collation, not just the rule used to sort the displayed list. SQLite index collations

Keep an unknown rule separate from an invalid input. Unknown / evidence unavailable makes no prediction about a custom collation. An unlisted profile, a number supplied instead of text, a tab, or a text value longer than the 32-character field limit is invalid. Empty text is valid and is not NULL; the simulation does not model NULL, type conversion, or RTRIM.

For accented text or locale-specific comparisons, use the rules for that implementation rather than extending the A/a result by eye. Equality, sort order, and the resulting uniqueness decision depend on the chosen comparison rule and the text it applies to.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Can equal-looking strings compare differently?

The comparison rule matters. In the bounded SQLite 3 example, A and a are distinct under BINARY but equal under built-in NOCASE. The input text is unchanged; the selected comparison rule changes the equality result.

Does case-insensitive mean accent-insensitive?

No broader equivalence is inferred. The SQLite built-in NOCASE rule used here folds ASCII letters only. Accented text and other Unicode cases return unknown rather than being approximated with a universal lowercase operation.

Can collation affect uniqueness?

In the declared uniqueness example, yes: one existing nonnull TEXT value conflicts when the new value compares equal under the same collation. The model does not evaluate arbitrary types, NULL policy or a live index.

Why are unsupported locales unknown?

They require their own documented rules. This lab implements only two named SQLite built-ins on printable ASCII, not arbitrary locale providers or Unicode normalization and sorting.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. Datatypes in SQLite

    7.1 Collating sequences; examples. BINARY compares byte representations; NOCASE folds ASCII uppercase only, not universal Unicode case folding.

    Checked .

  2. SQLite: CREATE INDEX

    Unique indexes and collations. Unique indexes reject duplicate index entries; an indexed column can specify a collation used for comparisons.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.