#28643: Complete the ORM Function Library
-------------------------------------+-------------------------------------
     Reporter:  Matthew Pava         |                    Owner:  JunyiJ
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Nick Pope:

Old description:

> I was surprised to learn that we didn't have a StrIndex function until
> version 2, and yet we had Substr since at least version 1.8.  I wonder
> how users were using Substr without also finding a use for StrIndex this
> whole time.  Anyway, since we seem to be adding these functions one at a
> time, why don't we work on trying to get the built-ins implemented in one
> sweep instead?
>
> We may even want to split the documentation page
> (https://docs.djangoproject.com/en/dev/ref/models/database-functions/)
> into further categories with String functions and Numeric functions.
>
> This is just a sample checklist, with corresponding attributes to which
> backend has them available.
>
> ||||||||||||||= **Comparison** =||
> ||**Name**||**Description**||**PostgreSQL**||**Oracle**||**MySQL**||**SQLite**||**PR**||
> ||NULLIF()||Returns NULL if the first argument equals the
> second.||X||X||X||X||[https://github.com/django/django/pull/9543 9543]||
> ||||||||||||||= **Math** =||
> ||**Name**||**Description**||**PostgreSQL**||**Oracle**||**MySQL**||**SQLite**||**PR**||
> ||ABS()||Returns the absolute
> value.||X||X||X||X||[https://github.com/django/django/pull/9577 9577]||
> ||ACOS()||Returns the arccosine.||X||X||X||-||-||
> ||ASIN()||Returns the arcsine.||X||X||X||-||-||
> ||ATAN()||Returns the arctangent.||X||X||X||-||-||
> ||ATAN2()||Returns the arctangent of the two variables passed to
> it.||X||X||X||-||-||
> ||CEILING()||Returns the smallest integer value that is not less than a
> numeric expression||X||as CEIL()||X||-||-||
> ||COS()||Returns the cosine expressed in radians.||X||X||X||-||-||
> ||COT()||Returns the cotangent.||X||X||X||-||-||
> ||DEGREES()||Returns a numeric expression converted from radians to
> degrees.||X||X||X||-||-||
> ||EXP()||Returns the base of the natural logarithm (e) raised to the
> power of a numeric expression.||X||X||X||-||-||
> ||FLOOR()||Returns the largest integer value that is not greater than a
> numeric expression.||X||X||X||-||-||
> ||LOG()||Returns the natural logarithm of a numeric
> expression.||X||X||X||-||-||
> ||MOD()||Returns the remainder of one expression by diving by another
> expression.||X||X||X||-||-||
> ||PI()||Returns the value of pi||X||-||X||-||-||
> ||POWER()||Returns the value of one expression raised to the power of
> another expression||X||X||X||-||-||
> ||RADIANS()||Returns the value of an expression converted from degrees to
> radians.||X||X||X||-||-||
> ||ROUND()||Returns a numeric expression rounded to an integer.\\Can be
> used to round an expression to a number of decimal
> points||X||X||X||X||-||
> ||SIN()||Returns the sine given in radians.||X||X||X||-||-||
> ||SQRT()||Returns the square root.||X||X||X||-||-||
> ||TAN()||Returns the tangent expressed in radians.||X||X||X||-||-||
> ||||||||||||||= **Text** =||
> ||**Name**||**Description**||**PostgreSQL**||**Oracle**||**MySQL**||**SQLite**||**PR**||
> ||ASCII() (In Python, it is ord())||Returns numeric value of left-most
> character||X||X||X||as
> UNICODE()||[https://github.com/django/django/pull/9583 9583]||
> ||CHR()||Character with the given code||X||X||as CHAR()||as
> CHAR()||[https://github.com/django/django/pull/9583 9583]||
> ||LEFT()||Returns the leftmost number of characters as specified||X||as
> SUBSTR()||X||as SUBSTR()||[https://github.com/django/django/pull/9583
> 9583]||
> ||LPAD()||Returns the string argument, left-padded with the specified
> string||X||X||X||-||-||
> ||LTRIM()||Removes leading
> spaces||X||X||X||X||[https://github.com/django/django/pull/9220 9220]||
> ||MD5()||Calculates the MD5 hash of string, returning the result in
> hexadecimal||X||-||-||-||-||
> ||REPEAT()||Repeats a string the specified number of
> times||X||-||X||-||-||
> ||REPLACE()||Replaces occurrences of a specified
> string||X||X||X||X||[https://github.com/django/django/pull/9539 9539]||
> ||REVERSE()||Reverse the characters in a string||X||-||X||-||-||
> ||RIGHT()||Returns the specified rightmost number of characters||X||as
> SUBSTR()||X||as SUBSTR()||[https://github.com/django/django/pull/9583
> 9583]||
> ||RPAD()||Appends string the specified number of times||X||X||X||-||-||
> ||RTRIM()||Removes trailing
> spaces||X||X||X||X||[https://github.com/django/django/pull/9220 9220]||
> ||TRIM()||Removes leading and trailing
> spaces||X||X||X||X||[https://github.com/django/django/pull/9220 9220]||

New description:

 I was surprised to learn that we didn't have a StrIndex function until
 version 2, and yet we had Substr since at least version 1.8.  I wonder how
 users were using Substr without also finding a use for StrIndex this whole
 time.  Anyway, since we seem to be adding these functions one at a time,
 why don't we work on trying to get the built-ins implemented in one sweep
 instead?

 We may even want to split the documentation page
 (https://docs.djangoproject.com/en/dev/ref/models/database-functions/)
 into further categories with String functions and Numeric functions.

 This is just a sample checklist, with corresponding attributes to which
 backend has them available.

 ||||||||||||||= **Comparison** =||
 
||**Name**||**Description**||**PostgreSQL**||**Oracle**||**MySQL**||**SQLite**||**PR**||
 ||{{{NULLIF}}}||Returns {{{NULL}}} if the first argument equals the
 second.||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9543
 9543]||
 ||||||||||||||= **Math** =||
 
||**Name**||**Description**||**PostgreSQL**||**Oracle**||**MySQL**||**SQLite**||**PR**||
 ||{{{ABS}}}||Returns the absolute
 value.||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9577 9577],
 [https://github.com/django/django/pull/9622 9622]||
 ||{{{ACOS}}}||Returns the
 arccosine.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{ASIN}}}||Returns the
 arcsine.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{ATAN}}}||Returns the
 arctangent.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{ATAN2}}}||Returns the arctangent of the two variables passed to
 it.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{CEILING}}}||Returns the smallest integer value that is not less than
 a numeric
 
expression||‎✔||{{{CEIL}}}||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{COS}}}||Returns the cosine expressed in
 radians.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{COT}}}||Returns the
 cotangent.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{DEGREES}}}||Returns a numeric expression converted from radians to
 degrees.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{EXP}}}||Returns the base of the natural logarithm (e) raised to the
 power of a numeric
 expression.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{FLOOR}}}||Returns the largest integer value that is not greater than
 a numeric
 expression.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{LOG}}}||Returns the natural logarithm of a numeric
 expression.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{MOD}}}||Returns the remainder of one expression by diving by another
 expression.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{PI}}}||Returns the value of
 π||‎✔||-||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{POWER}}}||Returns the value of one expression raised to the power of
 another
 expression||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{RADIANS}}}||Returns the value of an expression converted from degrees
 to
 radians.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{ROUND}}}||Returns a numeric expression rounded to an integer.\\Can be
 used to round an expression to a number of decimal
 points||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{SIN}}}||Returns the sine given in
 radians.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{SQRT}}}||Returns the square
 root.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||{{{TAN}}}||Returns the tangent expressed in
 radians.||‎✔||‎✔||‎✔||✔**^1^**||[https://github.com/django/django/pull/9622
 9622]||
 ||||||||||||||= **Text** =||
 
||**Name**||**Description**||**PostgreSQL**||**Oracle**||**MySQL**||**SQLite**||**PR**||
 ||{{{ASCII}}}||Returns numeric value of left-most character. (Equivalent
 to {{{ord()}}} in
 
Python.)||‎✔||‎✔||‎✔||{{{UNICODE}}}||[https://github.com/django/django/pull/9583
 9583]||
 ||{{{CHR}}}||Character with the given
 
code||‎✔||‎✔||{{{CHAR}}}||{{{CHAR}}}||[https://github.com/django/django/pull/9583
 9583]||
 ||{{{LEFT}}}||Returns the leftmost number of characters as
 
specified||‎✔||✔**^2^**||‎✔||✔**^2^**||[https://github.com/django/django/pull/9583
 9583]||
 ||{{{LPAD}}}||Returns the string argument, left-padded with the specified
 string||‎✔||‎✔||‎✔||-||-||
 ||{{{LTRIM}}}||Removes leading
 spaces||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9220
 9220]||
 ||{{{MD5}}}||Calculates the MD5 hash of string, returning the result in
 hexadecimal||‎✔||-||-||✔**^1^**||-||
 ||{{{REPEAT}}}||Repeats a string the specified number of
 times||‎✔||-||‎✔||-||-||
 ||{{{REPLACE}}}||Replaces occurrences of a specified
 string||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9539 9539]
 [[span(style=font-size:75%, (Merged))]]||
 ||{{{REVERSE}}}||Reverse the characters in a
 string||‎✔||-||‎✔||✔**^1^**||-||
 ||{{{RIGHT}}}||Returns the specified rightmost number of
 
characters||‎✔||✔**^2^**||‎✔||✔**^2^**||[https://github.com/django/django/pull/9583
 9583]||
 ||{{{RPAD}}}||Appends string the specified number of
 times||‎✔||‎✔||‎✔||-||-||
 ||{{{RTRIM}}}||Removes trailing
 spaces||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9220
 9220]||
 ||{{{TRIM}}}||Removes leading and trailing
 spaces||‎✔||‎✔||‎✔||‎✔||[https://github.com/django/django/pull/9220
 9220]||

 - **^1^** Function can be easily supported on SQLite with a
 
[https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
 user defined function].
 - **^2^** Behaviour can be emulated by using {{{SUBSTR}}}.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28643#comment:32>
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/064.9d15c90c6f9615e56b957865c394eb97%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to