features.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import operator
  2. from django.db import InterfaceError
  3. from django.db.backends.base.features import BaseDatabaseFeatures
  4. from django.utils.functional import cached_property
  5. class DatabaseFeatures(BaseDatabaseFeatures):
  6. allows_group_by_selected_pks = True
  7. can_return_columns_from_insert = True
  8. can_return_rows_from_bulk_insert = True
  9. has_real_datatype = True
  10. has_native_uuid_field = True
  11. has_native_duration_field = True
  12. has_native_json_field = True
  13. can_defer_constraint_checks = True
  14. has_select_for_update = True
  15. has_select_for_update_nowait = True
  16. has_select_for_update_of = True
  17. has_select_for_update_skip_locked = True
  18. has_select_for_no_key_update = True
  19. can_release_savepoints = True
  20. supports_tablespaces = True
  21. supports_transactions = True
  22. can_introspect_materialized_views = True
  23. can_distinct_on_fields = True
  24. can_rollback_ddl = True
  25. supports_combined_alters = True
  26. nulls_order_largest = True
  27. closed_cursor_error_class = InterfaceError
  28. has_case_insensitive_like = False
  29. greatest_least_ignores_nulls = True
  30. can_clone_databases = True
  31. supports_temporal_subtraction = True
  32. supports_slicing_ordering_in_compound = True
  33. create_test_procedure_without_params_sql = """
  34. CREATE FUNCTION test_procedure () RETURNS void AS $$
  35. DECLARE
  36. V_I INTEGER;
  37. BEGIN
  38. V_I := 1;
  39. END;
  40. $$ LANGUAGE plpgsql;"""
  41. create_test_procedure_with_int_param_sql = """
  42. CREATE FUNCTION test_procedure (P_I INTEGER) RETURNS void AS $$
  43. DECLARE
  44. V_I INTEGER;
  45. BEGIN
  46. V_I := P_I;
  47. END;
  48. $$ LANGUAGE plpgsql;"""
  49. requires_casted_case_in_updates = True
  50. supports_over_clause = True
  51. only_supports_unbounded_with_preceding_and_following = True
  52. supports_aggregate_filter_clause = True
  53. supported_explain_formats = {'JSON', 'TEXT', 'XML', 'YAML'}
  54. validates_explain_options = False # A query will error on invalid options.
  55. supports_deferrable_unique_constraints = True
  56. has_json_operators = True
  57. @cached_property
  58. def introspected_field_types(self):
  59. return {
  60. **super().introspected_field_types,
  61. 'PositiveBigIntegerField': 'BigIntegerField',
  62. 'PositiveIntegerField': 'IntegerField',
  63. 'PositiveSmallIntegerField': 'SmallIntegerField',
  64. }
  65. @cached_property
  66. def is_postgresql_10(self):
  67. return self.connection.pg_version >= 100000
  68. @cached_property
  69. def is_postgresql_11(self):
  70. return self.connection.pg_version >= 110000
  71. @cached_property
  72. def is_postgresql_12(self):
  73. return self.connection.pg_version >= 120000
  74. @cached_property
  75. def is_postgresql_13(self):
  76. return self.connection.pg_version >= 130000
  77. has_brin_autosummarize = property(operator.attrgetter('is_postgresql_10'))
  78. has_websearch_to_tsquery = property(operator.attrgetter('is_postgresql_11'))
  79. supports_table_partitions = property(operator.attrgetter('is_postgresql_10'))
  80. supports_covering_indexes = property(operator.attrgetter('is_postgresql_11'))
  81. supports_covering_gist_indexes = property(operator.attrgetter('is_postgresql_12'))