mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
Support PG_UNICODE_FAST locale in the builtin collation provider.
The PG_UNICODE_FAST locale uses code point sort order (fast, memcmp-based) combined with Unicode character semantics. The character semantics are based on Unicode full case mapping. Full case mapping can map a single codepoint to multiple codepoints, such as "ß" uppercasing to "SS". Additionally, it handles context-sensitive mappings like the "final sigma", and it uses titlecase mappings such as "Dž" when titlecasing (rather than plain uppercase mappings). Importantly, the uppercasing of "ß" as "SS" is specifically mentioned by the SQL standard. In Postgres, UCS_BASIC uses plain ASCII semantics for case mapping and pattern matching, so if we changed it to use the PG_UNICODE_FAST locale, it would offer better compliance with the standard. For now, though, do not change the behavior of UCS_BASIC. Discussion: https://postgr.es/m/ddfd67928818f138f51635712529bc5e1d25e4e7.camel@j-davis.com Discussion: https://postgr.es/m/27bb0e52-801d-4f73-a0a4-02cfdd4a9ada@eisentraut.org Reviewed-by: Peter Eisentraut, Daniel Verite
This commit is contained in:
@@ -80,3 +80,63 @@ SELECT 'xAb' ~* '[W-Y]' COLLATE PG_C_UTF8;
|
||||
SELECT 'xAb' !~* '[c-d]' COLLATE PG_C_UTF8;
|
||||
SELECT 'Δ' ~* '[γ-λ]' COLLATE PG_C_UTF8;
|
||||
SELECT 'δ' ~* '[Γ-Λ]' COLLATE PG_C_UTF8; -- same as above with cases reversed
|
||||
|
||||
--
|
||||
-- Test PG_UNICODE_FAST
|
||||
--
|
||||
|
||||
CREATE COLLATION regress_pg_unicode_fast (
|
||||
provider = builtin, locale = 'unicode'); -- fails
|
||||
CREATE COLLATION regress_pg_unicode_fast (
|
||||
provider = builtin, locale = 'PG_UNICODE_FAST');
|
||||
|
||||
CREATE TABLE test_pg_unicode_fast (
|
||||
t TEXT COLLATE PG_UNICODE_FAST
|
||||
);
|
||||
INSERT INTO test_pg_unicode_fast VALUES
|
||||
('abc DEF 123abc'),
|
||||
('ábc sßs ßss DÉF'),
|
||||
('DŽxxDŽ džxxDž Džxxdž'),
|
||||
('ȺȺȺ'),
|
||||
('ⱥⱥⱥ'),
|
||||
('ⱥȺ');
|
||||
|
||||
SELECT
|
||||
t, lower(t), initcap(t), upper(t),
|
||||
length(convert_to(t, 'UTF8')) AS t_bytes,
|
||||
length(convert_to(lower(t), 'UTF8')) AS lower_t_bytes,
|
||||
length(convert_to(initcap(t), 'UTF8')) AS initcap_t_bytes,
|
||||
length(convert_to(upper(t), 'UTF8')) AS upper_t_bytes
|
||||
FROM test_pg_unicode_fast;
|
||||
|
||||
DROP TABLE test_pg_unicode_fast;
|
||||
|
||||
-- test Final_Sigma
|
||||
SELECT lower('ΑΣ' COLLATE PG_UNICODE_FAST); -- 0391 03A3
|
||||
SELECT lower('ΑΣ0' COLLATE PG_UNICODE_FAST); -- 0391 03A3 0030
|
||||
SELECT lower('ἈΣ̓' COLLATE PG_UNICODE_FAST); -- 0391 0343 03A3 0343
|
||||
SELECT lower('ᾼΣͅ' COLLATE PG_UNICODE_FAST); -- 0391 0345 03A3 0345
|
||||
|
||||
-- test !Final_Sigma
|
||||
SELECT lower('Σ' COLLATE PG_UNICODE_FAST); -- 03A3
|
||||
SELECT lower('0Σ' COLLATE PG_UNICODE_FAST); -- 0030 03A3
|
||||
SELECT lower('ΑΣΑ' COLLATE PG_UNICODE_FAST); -- 0391 03A3 0391
|
||||
SELECT lower('ἈΣ̓Α' COLLATE PG_UNICODE_FAST); -- 0391 0343 03A3 0343 0391
|
||||
SELECT lower('ᾼΣͅΑ' COLLATE PG_UNICODE_FAST); -- 0391 0345 03A3 0345 0391
|
||||
|
||||
-- properties
|
||||
|
||||
SELECT 'xyz' ~ '[[:alnum:]]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT 'xyz' !~ '[[:upper:]]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT '@' !~ '[[:alnum:]]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT '=' !~ '[[:punct:]]' COLLATE PG_UNICODE_FAST; -- symbols are not punctuation
|
||||
SELECT 'a8a' ~ '[[:digit:]]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT '൧' ~ '\d' COLLATE PG_UNICODE_FAST;
|
||||
|
||||
-- case mapping
|
||||
|
||||
SELECT 'xYz' ~* 'XyZ' COLLATE PG_UNICODE_FAST;
|
||||
SELECT 'xAb' ~* '[W-Y]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT 'xAb' !~* '[c-d]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT 'Δ' ~* '[γ-λ]' COLLATE PG_UNICODE_FAST;
|
||||
SELECT 'δ' ~* '[Γ-Λ]' COLLATE PG_UNICODE_FAST; -- same as above with cases reversed
|
||||
|
||||
Reference in New Issue
Block a user