Debian Codegraph @

contrib/citext/sql/citext_utf8.sql

raw
1 /*
2 * This test must be run in a database with UTF-8 encoding
3 * and a Unicode-aware locale.
4 *
5 * Also disable this file for ICU, because the test for the
6 * Turkish dotted I is not correct for many ICU locales. citext always
7 * uses the default collation, so it's not easy to restrict the test
8 * to the "tr-TR-x-icu" collation where it will succeed.
9 *
10 * Also disable for Windows. It fails similarly, at least in some locales.
11 */
12
13 SELECT getdatabaseencoding() <> 'UTF8' OR
14 version() ~ '(Visual C\+\+|mingw32|windows)' OR
15 (SELECT (datlocprovider = 'c' AND datctype = 'C') OR datlocprovider = 'i'
16 FROM pg_database
17 WHERE datname=current_database())
18 AS skip_test \gset
19 \if :skip_test
20 \quit
21 \endif
22
23 set client_encoding = utf8;
24
25 -- CREATE EXTENSION IF NOT EXISTS citext;
26
27 -- Multibyte sanity tests.
28 SELECT 'À'::citext = 'À'::citext AS t;
29 SELECT 'À'::citext = 'à'::citext AS t;
30 SELECT 'À'::text = 'à'::text AS f; -- text wins.
31 SELECT 'À'::citext <> 'B'::citext AS t;
32
33 -- Test combining characters making up canonically equivalent strings.
34 SELECT 'Ä'::text <> 'Ä'::text AS t;
35 SELECT 'Ä'::citext <> 'Ä'::citext AS t;
36
37 -- Test the Turkish dotted I. The lowercase is a single byte while the
38 -- uppercase is multibyte. This is why the comparison code can't be optimized
39 -- to compare string lengths.
40 SELECT 'i'::citext = 'İ'::citext AS t;
41
42 -- Regression.
43 SELECT 'láska'::citext <> 'laská'::citext AS t;
44
45 SELECT 'Ask Bjørn Hansen'::citext = 'Ask Bjørn Hansen'::citext AS t;
46 SELECT 'Ask Bjørn Hansen'::citext = 'ASK BJØRN HANSEN'::citext AS t;
47 SELECT 'Ask Bjørn Hansen'::citext <> 'Ask Bjorn Hansen'::citext AS t;
48 SELECT 'Ask Bjørn Hansen'::citext <> 'ASK BJORN HANSEN'::citext AS t;
49 SELECT citext_cmp('Ask Bjørn Hansen'::citext, 'Ask Bjørn Hansen'::citext) = 0 AS t;
50 SELECT citext_cmp('Ask Bjørn Hansen'::citext, 'ask bjørn hansen'::citext) = 0 AS t;
51 SELECT citext_cmp('Ask Bjørn Hansen'::citext, 'ASK BJØRN HANSEN'::citext) = 0 AS t;
52 SELECT citext_cmp('Ask Bjørn Hansen'::citext, 'Ask Bjorn Hansen'::citext) > 0 AS t;
53 SELECT citext_cmp('Ask Bjorn Hansen'::citext, 'Ask Bjørn Hansen'::citext) < 0 AS t;
54
55 -- Test ~<~ and ~<=~
56 SELECT 'à'::citext ~<~ 'À'::citext AS f;
57 SELECT 'à'::citext ~<=~ 'À'::citext AS t;
58
59 -- Test ~>~ and ~>=~
60 SELECT 'à'::citext ~>~ 'À'::citext AS f;
61 SELECT 'à'::citext ~>=~ 'À'::citext AS t;