summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBrad Melin <melinbrad@gmail.com>2017-02-21 08:43:38 +0200
committerTim Graham <timograham@gmail.com>2017-03-14 19:58:56 -0400
commitb625907a79bb1336cbc54231bdf7cace25fecaf7 (patch)
tree824ee84d7123c31c87860e137dc48806be5b6cb8 /docs
parent3f64fd2f75342fa061338d75916c08b98f0c7797 (diff)
Fixed #27834 -- Added StrIndex database function.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/database-functions.txt32
-rw-r--r--docs/releases/2.0.txt3
2 files changed, 34 insertions, 1 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt
index 18d547d906..21b6f897ac 100644
--- a/docs/ref/models/database-functions.txt
+++ b/docs/ref/models/database-functions.txt
@@ -237,6 +237,38 @@ Usage example::
``Now()`` uses ``STATEMENT_TIMESTAMP`` instead. If you need the transaction
timestamp, use :class:`django.contrib.postgres.functions.TransactionNow`.
+``StrIndex``
+============
+
+.. class:: StrIndex(expression, substring, **extra)
+
+.. versionadded:: 2.0
+
+Returns a positive integer corresponding to the 1-indexed position of the
+first occurrence of ``substring`` inside another string, or 0 if the substring
+is not found.
+
+Usage example::
+
+ >>> from django.db.models.functions import StrIndex
+ >>> Author.objects.create(name='Margaret Smith')
+ >>> Author.objects.create(name='Smith, Margaret')
+ >>> Author.objects.create(name='Margaret Jackson')
+ >>> authors = Author.objects.annotate(
+ ... smith_index=StrIndex('name', 'Smith')).order_by('smith_index')
+ >>> authors.first().smith_index
+ 0
+ >>> authors = Author.objects.annotate(
+ ... smith_index=StrIndex('name', 'Smith')).filter(smith_index__gt=0)
+ <QuerySet [<Author: Margaret Smith>, <Author: Smith, Margaret>]>
+
+.. warning::
+
+ In MySQL, a database table's :ref:`collation<mysql-collation>` determines
+ whether string comparisons (such as the ``expression`` and ``substring`` of
+ this function) are case-sensitive. Comparisons are case-insensitive by
+ default.
+
``Substr``
==========
diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt
index 4592d8b76d..369a5893ba 100644
--- a/docs/releases/2.0.txt
+++ b/docs/releases/2.0.txt
@@ -170,7 +170,8 @@ Migrations
Models
~~~~~~
-* ...
+* The new :class:`~django.db.models.functions.StrIndex` database function
+ finds the starting index of a string inside another string.
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~