#27834: Add the STRPOS database function
-------------------------------------+-------------------------------------
               Reporter:  Baptiste   |          Owner:  nobody
  Mispelon                           |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  1.10
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django currently ships with a dozen or so database functions [1].

 I recently had the need for what postgres calls `STRPOS(string,
 substring)` to find the position of a string inside a substring and was
 surprised to find it was not included in the list of builtins.

 I'm not sure if there's an official criteria for deciding which functions
 get implemented in core, but I did some quick research and found that this
 `STRPOS()` functionality at least seems to be present in all 4 officially
 supported databases:

 * **Postgres**: `STRPOS(string, substring)` [2]
 * **Sqlite**: `INSTR(string, substring)` [3]
 * **MySQL**: `LOCATE(substring, string)` [4]
 * **Oracle**: `INSTR(string, substring)` [5]

 The names and order of arguments are somewhat inconsistent but the
 behavior and return value of the function seems well-defined: it returns a
 positive integer corresponding to the (1-indexed) position of the
 substring inside the string; if the substring is not found, 0 is returned.


 I'm marking this as "easy pickings" because other than the inconsistent
 naming and argument order, the actual implementation of the `Func`
 shouldn't be too complex.

 [1] https://docs.djangoproject.com/en/dev/ref/models/database-functions/
 [2] https://www.postgresql.org/docs/current/static/functions-string.html
 [3] https://www.sqlite.org/lang_corefunc.html#instr
 [4] https://dev.mysql.com/doc/refman/5.7/en/string-
 functions.html#function_locate
 [5]
 https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions068.htm

--
Ticket URL: <https://code.djangoproject.com/ticket/27834>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.232a0663b8910babf157447be894a12f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to