From e387f191f76777015b6ea687ce83cdb05ee47cee Mon Sep 17 00:00:00 2001 From: Tom Carrick Date: Sat, 18 Jul 2020 13:17:39 +0200 Subject: Fixed #31777 -- Added support for database collations to Char/TextFields. Thanks Simon Charette and Mariusz Felisiak for reviews. --- django/db/backends/postgresql/features.py | 2 ++ django/db/backends/postgresql/introspection.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'django/db/backends/postgresql') diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py index 9080e75a36..e70ef4e95d 100644 --- a/django/db/backends/postgresql/features.py +++ b/django/db/backends/postgresql/features.py @@ -59,6 +59,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): has_json_operators = True json_key_contains_list_matching_requires_list = True test_collations = { + 'non_default': 'sv-x-icu', 'swedish_ci': 'sv-x-icu', } @@ -92,3 +93,4 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_table_partitions = property(operator.attrgetter('is_postgresql_10')) supports_covering_indexes = property(operator.attrgetter('is_postgresql_11')) supports_covering_gist_indexes = property(operator.attrgetter('is_postgresql_12')) + supports_non_deterministic_collations = property(operator.attrgetter('is_postgresql_12')) diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index b7952eaed7..a0e49c8da7 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -69,9 +69,11 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): SELECT a.attname AS column_name, NOT (a.attnotnull OR (t.typtype = 'd' AND t.typnotnull)) AS is_nullable, - pg_get_expr(ad.adbin, ad.adrelid) AS column_default + pg_get_expr(ad.adbin, ad.adrelid) AS column_default, + CASE WHEN collname = 'default' THEN NULL ELSE collname END AS collation FROM pg_attribute a LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum + LEFT JOIN pg_collation co ON a.attcollation = co.oid JOIN pg_type t ON a.atttypid = t.oid JOIN pg_class c ON a.attrelid = c.oid JOIN pg_namespace n ON c.relnamespace = n.oid -- cgit v1.3