summaryrefslogtreecommitdiff
path: root/django/db/models/functions/math.py
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2020-07-16 23:32:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-02 06:58:03 +0200
commit06c5d3fafc6aeb96387148726713b611aeba7fa1 (patch)
tree80a366cad2aa8caf22062d6eb5f4487c36a000e2 /django/db/models/functions/math.py
parentf87b0ecd37e64e7a019d472de37d0789a8790f1f (diff)
downloaddjango-06c5d3fafc6aeb96387148726713b611aeba7fa1.tar.gz
Fixed #32060 -- Added Random database function.
Diffstat (limited to 'django/db/models/functions/math.py')
-rw-r--r--django/db/models/functions/math.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/django/db/models/functions/math.py b/django/db/models/functions/math.py
index 909a3088bb..304e112225 100644
--- a/django/db/models/functions/math.py
+++ b/django/db/models/functions/math.py
@@ -141,6 +141,20 @@ class Radians(NumericOutputFieldMixin, Transform):
)
+class Random(NumericOutputFieldMixin, Func):
+ function = 'RANDOM'
+ arity = 0
+
+ def as_mysql(self, compiler, connection, **extra_context):
+ return super().as_sql(compiler, connection, function='RAND', **extra_context)
+
+ def as_oracle(self, compiler, connection, **extra_context):
+ return super().as_sql(compiler, connection, function='DBMS_RANDOM.VALUE', **extra_context)
+
+ def as_sqlite(self, compiler, connection, **extra_context):
+ return super().as_sql(compiler, connection, function='RAND', **extra_context)
+
+
class Round(Transform):
function = 'ROUND'
lookup_name = 'round'