﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27834	Add the STRPOS database function	Baptiste Mispelon	Brad Melin	"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"	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	expressions	josh.smeaton@…	Accepted	1	0	0	0	0	0
