Commits

Kirill Simonov committed 4c704bb

Updated the string function reference.

Comments (0)

Files changed (1)

doc/reference.rst

 expected, it is automatically cast.  Hence, for convenience, we write
 string typed values using single quotes in the output column.
 
-+----------------+------------------+----------------------+---------------+
-| Function       | Description      | Example Input        | Output        |
-+================+==================+======================+===============+
-| string(x)      | cast to string   | string('Hello')      | 'Hello'       |
-|                |                  +----------------------+---------------+
-|                |                  | string(1.0)          | '1.0'         |
-|                |                  +----------------------+---------------+
-|                |                  | string(``null()``)   | ``null()``    |
-|                |                  +----------------------+---------------+
-|                |                  | string(``true()``)   | 'true'        |
-|                |                  +----------------------+---------------+
-|                |                  | string(``false()``)  | 'false'       |
-+----------------+------------------+----------------------+---------------+
-| x + y          | concatenation;   | 'Hello' + ' World'   | 'Hello World' |
-|                | treats nulls as  +----------------------+---------------+
-|                | empty strings    | 'Hello' + ``null()`` | 'Hello'       |
-+----------------+------------------+----------------------+---------------+
-| x ~ y          | case-insensitive | 'HTSQL' ~ 'sql'      | ``true()``    |
-|                | string contains  |                      |               |
-+----------------+------------------+----------------------+---------------+
-| x !~ y         | case-insensitive | 'HTSQL' !~ 'sql'     | ``false()``   |
-|                | not contains     |                      |               |
-+----------------+------------------+----------------------+---------------+
-| head(s,n=1)    | returns first n  | head('HTSQL', 2)     | 'HT'          |
-|                | characters of s  +----------------------+---------------+
-|                |                  | head('HTSQL')        | 'H'           |
-+----------------+------------------+----------------------+---------------+
-| tail(s,n=1)    | returns last n   | tail('HTSQL', 3)     | 'SQL'         |
-|                | characters of s  +----------------------+---------------+
-|                |                  | tail('HTSQL')        | 'L'           |
-+----------------+------------------+----------------------+---------------+
-| slice(s,i,     | chars i to j     | slice('HTSQL',2,5)   | 'SQL'         |
-|       j=-1)    | characters of s  +----------------------+---------------+
-|                |                  | slice('HTSQL',2)     | 'SQL'         |
-|                |                  +----------------------+---------------+
-|                |                  | slice('HTSQL',-3)    | 'SQL'         |
-+----------------+------------------+----------------------+---------------+
-| at(s,k,n=1)    | return n chars   | at('HTSQL',2)        | 'S'           |
-|                | starting with k  +----------------------+---------------+
-|                |                  | at('HTSQL,2,3)       | 'SQL'         |
-|                |                  +----------------------+---------------+
-|                |                  | at('HTSQL,-3,3)      | 'SQL'         |
-+----------------+------------------+----------------------+---------------+
-| upper(s)       | returns upper    | upper('htsql')       | 'HTSQL'       |
-|                | case of s        |                      |               |
-+----------------+------------------+----------------------+---------------+
-| lower(s)       | returns lower    | lower('HTSQL')       | 'htsql'       |
-|                | case of s        |                      |               |
-+----------------+------------------+----------------------+---------------+
-| replace(s,x,y) | replaces all     | replace('HTSQL',     | 'HTRAF'       |
-|                | occurrences of x |         'SQL','RAF') |               |
-|                | in s with y      |                      |               |
-+----------------+------------------+----------------------+---------------+
-| ltrim(s)       | strips leading   | ltrim('  HTSQL  ')   | 'HTSQL  '     |
-|                | spaces from s    |                      |               |
-+----------------+------------------+----------------------+---------------+
-| rtrim(s)       | strips trailing  | rtrim('  HTSQL  ')   | '  HTSQL'     |
-|                | spaces from s    |                      |               |
-+----------------+------------------+----------------------+---------------+
-| trim(s)        | strips leading   | trim('  HTSQL  ')    | 'HTSQL'       |
-|                | and trailing     +----------------------+---------------+
-|                | spaces from s    | trim('HTSQL')        | 'HTSQL'       |
-+----------------+------------------+----------------------+---------------+
++----------------------+---------------------------+---------------------------+----------------------+
+| Function             | Description               | Example Input             | Output               |
++======================+===========================+===========================+======================+
+| `string(x)`          | cast *x* to string        | ``string('Hello')``       | ``'Hello'``          |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | ``string(1.0)``           | ``'1.0'``            |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | ``string(null())``        | ``null()``           |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | ``string(true())``        | ``'true'``           |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | ``string(false())``       | ``'false'``          |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | |string-from-date-in|     | ``'2010-04-15'``     |
++----------------------+---------------------------+---------------------------+----------------------+
+| `length(s)`          | number of characters      | ``length('HTSQL')``       | ``5``                |
+|                      | in *s*                    |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `x + y`              | concatenate *x* and *y*;  | ``'Hello' + ' World'``    | ``'Hello World'``    |
+|                      | treats nulls as empty     +---------------------------+----------------------+
+|                      | strings                   | ``'Hello' + null()``      | ``'Hello'``          |
+|                      |                           |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `x ~ y`              | *x* contains *y*;         | ``'HTSQL' ~ 'sql'``       | ``true()``           |
+|                      | case-insensitive          |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `x !~ y`             | *x* does not contain      | ``'HTSQL' !~ 'sql'``      | ``false()``          |
+|                      | *y*; case-insensitive     |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `head(s)`            | first character of *s*    | ``head('HTSQL')``         | ``'H'``              |
++----------------------+---------------------------+---------------------------+----------------------+
+| `head(s,n)`          | first *n* characters      | ``head('HTSQL',2)``       | ``'HT'``             |
+|                      | of *s*                    +---------------------------+----------------------+
+|                      |                           | ``head('HTSQL',-3)``      | ``'HT'``             |
++----------------------+---------------------------+---------------------------+----------------------+
+| `tail(s)`            | last character of *s*     | ``tail('HTSQL')``         | ``'L'``              |
++----------------------+---------------------------+---------------------------+----------------------+
+| `tail(s,n)`          | last *n* characters       | ``tail('HTSQL',3)``       | ``'SQL'``            |
+|                      | of *s*                    +---------------------------+----------------------+
+|                      |                           | ``tail('HTSQL',-2)``      | ``'SQL'``            |
++----------------------+---------------------------+---------------------------+----------------------+
+| `slice(s,i,j)`       | *i*-th to *j*-th          | ``slice('HTSQL',1,4)``    | ``'TSQ'``            |
+|                      | characters of *s*; null   +---------------------------+----------------------+
+|                      | or missing index means    | ``slice('HTSQL',-4,-1)``  | ``'TSQ'``            |
+|                      | the beginning or the end  +---------------------------+----------------------+
+|                      | of the string             | |slice-start-in|          | ``'HT'``             |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | |slice-end-in|            | ``'SQL'``            |
++----------------------+---------------------------+---------------------------+----------------------+
+| `at(s,k)`            | *k*-th character of *s*   | ``at('HTSQL',2)``         | ``'S'``              |
++----------------------+---------------------------+---------------------------+----------------------+
+| `at(s,k,n)`          | *n* characters of *s*     | ``at('HTSQL',1,3)``       | ``'TSQ'``            |
+|                      | starting with *k*-th      +---------------------------+----------------------+
+|                      | character                 | ``at('HTSQL,-4,3)``       | ``'TSQ'``            |
+|                      |                           +---------------------------+----------------------+
+|                      |                           | ``at('HTSQL,4,-3)``       | ``'TSQ'``            |
++----------------------+---------------------------+---------------------------+----------------------+
+| `upper(s)`           | upper case of *s*         | ``upper('htsql')``        | ``'HTSQL'``          |
++----------------------+---------------------------+---------------------------+----------------------+
+| `lower(s)`           | lower case of *s*         | ``lower('HTSQL')``        | ``'htsql'``          |
++----------------------+---------------------------+---------------------------+----------------------+
+| `trim(s)`            | strip leading and         | ``trim('  HTSQL  ')``     | ``'HTSQL'``          |
+|                      | trailing spaces from *s*  |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `ltrim(s)`           | strip leading spaces      | ``ltrim('  HTSQL  ')``    | ``'HTSQL  '``        |
+|                      | from *s*                  |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `rtrim(s)`           | strips trailing spaces    | ``rtrim('  HTSQL  ')``    | ``'  HTSQL'``        |
+|                      | from *s*                  |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
+| `replace(s,x,y)`     | replace all occurences    | |replace-in|              | ``'HTRAF'``          |
+|                      | of *x* in *s* with *y*;   +---------------------------+----------------------+
+|                      | in *s* with *y*; null *x* | |replace-null-in|         | ``'HTSQL'``          |
+|                      | is treated as an empty    |                           |                      |
+|                      | string                    |                           |                      |
++----------------------+---------------------------+---------------------------+----------------------+
 
+.. |string-from-date-in| replace:: ``string(date('2010-04-15'))``
+.. |slice-start-in| replace:: ``slice('HTSQL',null(),2)``
+.. |slice-end-in| replace:: ``slice('HTSQL',2,null())``
+.. |replace-in| replace:: ``replace('HTSQL','SQL','RAF')``
+.. |replace-null-in| replace:: ``replace('HTSQL',null(),'RAF')``
+