How to change the collation of sqlite3 database to sort case insensitively?

前端 未结 4 1826
小鲜肉
小鲜肉 2020-12-10 11:22

I have a query for sqlite3 database which provides the sorted data. The data are sorted on the basis of a column which is a varchar column \"Name\". Now when I

4条回答
  •  -上瘾入骨i
    2020-12-10 12:09

    The SQLite Datatypes documentation discusses user-defined collation sequences. Specifically you use COLLATE NOCASE to achieve your goal.

    They give an example:

    CREATE TABLE t1(
        a,                 -- default collation type BINARY
        b COLLATE BINARY,  -- default collation type BINARY
        c COLLATE REVERSE, -- default collation type REVERSE
        d COLLATE NOCASE   -- default collation type NOCASE
    );
    

    and note that:

    -- Grouping is performed using the NOCASE collation sequence (i.e. values -- 'abc' and 'ABC' are placed in the same group). SELECT count(*) GROUP BY d FROM t1;

提交回复
热议问题