From ddb85294159185c5bd5cae34c9ef735ff8409bfe Mon Sep 17 00:00:00 2001 From: ontowhee <82607723+ontowhee@users.noreply.github.com> Date: Sat, 15 Mar 2025 19:23:28 -0700 Subject: Fixed #34262 -- Added support for AnyValue for SQLite, MySQL, Oracle, and Postgresql 16+. Thanks Simon Charette for the guidance and review. Thanks Tim Schilling for the documentation review. Thanks David Wobrock for investigation and solution proposals. --- django/db/backends/sqlite3/_functions.py | 6 ++++++ django/db/backends/sqlite3/features.py | 1 + 2 files changed, 7 insertions(+) (limited to 'django/db/backends/sqlite3') diff --git a/django/db/backends/sqlite3/_functions.py b/django/db/backends/sqlite3/_functions.py index 6d07d3d78b..b38e06eec2 100644 --- a/django/db/backends/sqlite3/_functions.py +++ b/django/db/backends/sqlite3/_functions.py @@ -80,6 +80,7 @@ def register(connection): connection.create_aggregate("STDDEV_SAMP", 1, StdDevSamp) connection.create_aggregate("VAR_POP", 1, VarPop) connection.create_aggregate("VAR_SAMP", 1, VarSamp) + connection.create_aggregate("ANY_VALUE", 1, AnyValue) # Some math functions are enabled by default in SQLite 3.35+. sql = "select sqlite_compileoption_used('ENABLE_MATH_FUNCTIONS')" if not connection.execute(sql).fetchone()[0]: @@ -513,3 +514,8 @@ class VarPop(ListAggregate): class VarSamp(ListAggregate): finalize = statistics.variance + + +class AnyValue(ListAggregate): + def finalize(self): + return self[0] diff --git a/django/db/backends/sqlite3/features.py b/django/db/backends/sqlite3/features.py index 1e995a87c0..8604adf40a 100644 --- a/django/db/backends/sqlite3/features.py +++ b/django/db/backends/sqlite3/features.py @@ -36,6 +36,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_aggregate_filter_clause = True supports_aggregate_order_by_clause = Database.sqlite_version_info >= (3, 44, 0) supports_aggregate_distinct_multiple_argument = False + supports_any_value = True order_by_nulls_first = True supports_json_field_contains = False supports_update_conflicts = True -- cgit v1.3