SQL: functions docs update (#34000)

* Changed the format of the String functions documentation page.
* Adopted the same format for Math functions, but completely changed the examples.
* Added missing documentation for Math functions.
This commit is contained in:
Andrei Stefan 2018-09-25 02:42:18 +03:00 committed by GitHub
parent 704d3e4c24
commit 0fae6d39f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1117 additions and 197 deletions

View File

@ -8,68 +8,276 @@ to be numeric.
==== Generic
* `ABS`
[[sql-functions-math-abs]]
===== `ABS`
https://en.wikipedia.org/wiki/Absolute_value[Absolute value], returns \[same type as input]
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[abs]
ABS(numeric_exp<1>)
--------------------------------------------------
* `CBRT`
*Input*:
https://en.wikipedia.org/wiki/Cube_root[Cube root], returns `double`
<1> numeric expression
// TODO make the example in the tests presentable
*Output*: numeric
* `CEIL`
.Description:
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Ceiling], returns `double`
Returns the https://en.wikipedia.org/wiki/Absolute_value[absolute value] of `numeric_exp`. The return type is the same as the input type.
* `CEILING`
Same as `CEIL`
// TODO make the example in the tests presentable
* `E`
https://en.wikipedia.org/wiki/E_%28mathematical_constant%29[Euler's number], returns `2.7182818284590452354`
* https://en.wikipedia.org/wiki/Exponential_function[e^x^] (`EXP`)
["source","sql",subs="attributes,callouts,macros"]
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[exp]
include-tagged::{sql-specs}/docs.csv-spec[abs]
--------------------------------------------------
* https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[e^x^ - 1] (`EXPM1`)
[[sql-functions-math-cbrt]]
===== `CBRT`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[expm1]
CBRT(numeric_exp<1>)
--------------------------------------------------
* https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Floor] (`FLOOR`)
*Input*:
// TODO make the example in the tests presentable
<1> numeric expression
* https://en.wikipedia.org/wiki/Natural_logarithm[Natural logarithm] (`LOG`)
*Output*: double numeric value
["source","sql",subs="attributes,callouts,macros"]
.Description:
Returns the https://en.wikipedia.org/wiki/Cube_root[cube root] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[log]
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCbrtWithNegativeValue]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Logarithm[Logarithm] base 10 (`LOG10`)
[[sql-functions-math-ceil]]
===== `CEIL/CEILING`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[log10]
CEIL(numeric_exp<1>)
CEILING(numeric_exp<2>)
--------------------------------------------------
* `ROUND`
*Input*:
<1> numeric expression
<2> numeric expression
*Output*: integer or long numeric value
.Description:
Returns the smallest integer greater than or equal to `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCeiling]
--------------------------------------------------
[[sql-functions-math-e]]
===== `E`
.Synopsis:
[source, sql]
--------------------------------------------------
E()
--------------------------------------------------
*Input*: _none_
*Output*: `2.718281828459045`
.Description:
Returns https://en.wikipedia.org/wiki/E_%28mathematical_constant%29[Euler's number].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathEulersNumber]
--------------------------------------------------
[[sql-functions-math-exp]]
===== `EXP`
.Synopsis:
[source, sql]
--------------------------------------------------
EXP(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> float numeric expression
*Output*: double numeric value
.Description:
Returns https://en.wikipedia.org/wiki/Exponential_function[Euler's number at the power] of `numeric_exp` e^numeric_exp^.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathExpInline]
--------------------------------------------------
[[sql-functions-math-expm1]]
===== `EXPM1`
.Synopsis:
[source, sql]
--------------------------------------------------
EXPM1(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> float numeric expression
*Output*: double numeric value
.Description:
Returns https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[Euler's number at the power] of `numeric_exp` minus 1 (e^numeric_exp^ - 1).
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathExpm1Inline]
--------------------------------------------------
[[sql-functions-math-floor]]
===== `FLOOR`
.Synopsis:
[source, sql]
--------------------------------------------------
FLOOR(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: integer or long numeric value
.Description:
Returns the largest integer less than or equal to `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineFloor]
--------------------------------------------------
[[sql-functions-math-log]]
===== `LOG`
.Synopsis:
[source, sql]
--------------------------------------------------
LOG(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Natural_logarithm[natural logarithm] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog]
--------------------------------------------------
[[sql-functions-math-log10]]
===== `LOG10`
.Synopsis:
[source, sql]
--------------------------------------------------
LOG10(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Common_logarithm[base 10 logarithm] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog10]
--------------------------------------------------
[[sql-functions-math-pi]]
===== `PI`
.Synopsis:
[source, sql]
--------------------------------------------------
PI()
--------------------------------------------------
*Input*: _none_
*Output*: `3.141592653589793`
.Description:
Returns https://en.wikipedia.org/wiki/Pi[PI number].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathPINumber]
--------------------------------------------------
[[sql-functions-math-power]]
===== `POWER`
.Synopsis:
[source, sql]
--------------------------------------------------
POWER(numeric_exp<1>, integer_exp<2>)
--------------------------------------------------
*Input*:
<1> numeric expression
<2> integer expression
*Output*: double numeric value
.Description:
Returns the value of `numeric_exp` to the power of `integer_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlinePowerPositive]
--------------------------------------------------
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlinePowerNegative]
--------------------------------------------------
[[sql-functions-math-round]]
===== `ROUND`
.Synopsis:
[source, sql]
@ -78,8 +286,8 @@ ROUND(numeric_exp<1>[, integer_exp<2>])
----
*Input*:
<1> numeric expression
<2> integer expression; optional
<1> numeric expression
<2> integer expression; optional
*Output*: numeric
@ -89,24 +297,67 @@ Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point
the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
of `numeric_exp`.
["source","sql",subs="attributes,callouts,macros"]
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithPositiveParameter]
--------------------------------------------------
["source","sql",subs="attributes,callouts,macros"]
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithNegativeParameter]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Square_root[Square root] (`SQRT`)
[[sql-functions-math-sign]]
===== `SIGN`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[sqrt]
SIGN(numeric_exp<1>)
--------------------------------------------------
* `TRUNCATE`
*Input*:
<1> numeric expression
*Output*: [-1, 0, 1]
.Description:
Returns an indicator of the sign of `numeric_exp`. If `numeric_exp` is less than zero, 1 is returned. If `numeric_exp` equals zero, 0 is returned. If `numeric_exp` is greater than zero, 1 is returned.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSign]
--------------------------------------------------
[[sql-functions-math-sqrt]]
===== `SQRT`
.Synopsis:
[source, sql]
--------------------------------------------------
SQRT(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns https://en.wikipedia.org/wiki/Square_root[square root] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSqrt]
--------------------------------------------------
[[sql-functions-math-truncate]]
===== `TRUNCATE`
.Synopsis:
[source, sql]
@ -115,8 +366,8 @@ TRUNCATE(numeric_exp<1>[, integer_exp<2>])
----
*Input*:
<1> numeric expression
<2> integer expression; optional
<1> numeric expression
<2> integer expression; optional
*Output*: numeric
@ -126,86 +377,305 @@ Returns `numeric_exp` truncated to `integer_exp` places right of the decimal poi
the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
of `numeric_exp`.
["source","sql",subs="attributes,callouts,macros"]
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithPositiveParameter]
--------------------------------------------------
["source","sql",subs="attributes,callouts,macros"]
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithNegativeParameter]
--------------------------------------------------
==== Trigonometric
* Convert from https://en.wikipedia.org/wiki/Radian[radians]
to https://en.wikipedia.org/wiki/Degree_(angle)[degrees] (`DEGREES`)
[[sql-functions-math-acos]]
===== `ACOS`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[degrees]
ACOS(numeric_exp<1>)
--------------------------------------------------
* Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
to https://en.wikipedia.org/wiki/Radian[radians] (`RADIANS`)
*Input*:
["source","sql",subs="attributes,callouts,macros"]
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arccosine] of `numeric_exp` as an angle, expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[degrees]
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAcos]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Trigonometric_functions#sine[Sine] (`SIN`)
[[sql-functions-math-asin]]
===== `ASIN`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[sin]
ASIN(numeric_exp<1>)
--------------------------------------------------
* https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[Cosine] (`COS`)
*Input*:
["source","sql",subs="attributes,callouts,macros"]
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arcsine] of `numeric_exp` as an angle, expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[cos]
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAsin]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[Tangent] (`TAN`)
[[sql-functions-math-atan]]
===== `ATAN`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[tan]
ATAN(numeric_exp<1>)
--------------------------------------------------
* https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc sine] (`ASIN`)
*Input*:
["source","sql",subs="attributes,callouts,macros"]
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[asin]
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc cosine] (`ACOS`)
[[sql-functions-math-atan2]]
===== `ATAN2`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[acos]
ATAN2(ordinate<1>, abscisa<2>)
--------------------------------------------------
* https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc tangent] (`ATAN`)
*Input*:
["source","sql",subs="attributes,callouts,macros"]
<1> numeric expression
<2> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[atan]
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan2]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Hyperbolic_function[Hyperbolic sine] (`SINH`)
[[sql-functions-math-cos]]
===== `COS`
["source","sql",subs="attributes,callouts,macros"]
.Synopsis:
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[sinh]
COS(numeric_exp<1>)
--------------------------------------------------
* https://en.wikipedia.org/wiki/Hyperbolic_function[Hyperbolic cosine] (`COSH`)
*Input*:
["source","sql",subs="attributes,callouts,macros"]
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[cosh]
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosine]
--------------------------------------------------
[[sql-functions-math-cosh]]
===== `COSH`
.Synopsis:
[source, sql]
--------------------------------------------------
COSH(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosh]
--------------------------------------------------
[[sql-functions-math-cot]]
===== `COT`
.Synopsis:
[source, sql]
--------------------------------------------------
COT(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#Cosecant,_secant,_and_cotangent[cotangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCotangent]
--------------------------------------------------
[[sql-functions-math-degrees]]
===== `DEGREES`
.Synopsis:
[source, sql]
--------------------------------------------------
DEGREES(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Convert from https://en.wikipedia.org/wiki/Radian[radians]
to https://en.wikipedia.org/wiki/Degree_(angle)[degrees].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineDegrees]
--------------------------------------------------
[[sql-functions-math-radians]]
===== `RADIANS`
.Synopsis:
[source, sql]
--------------------------------------------------
RADIANS(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
to https://en.wikipedia.org/wiki/Radian[radians].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineRadians]
--------------------------------------------------
[[sql-functions-math-sin]]
===== `SIN`
.Synopsis:
[source, sql]
--------------------------------------------------
SIN(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSine]
--------------------------------------------------
[[sql-functions-math-sinh]]
===== `SINH`
.Synopsis:
[source, sql]
--------------------------------------------------
SINH(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSinh]
--------------------------------------------------
[[sql-functions-math-tan]]
===== `TAN`
.Synopsis:
[source, sql]
--------------------------------------------------
TAN(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineTanget]
--------------------------------------------------

View File

@ -8,233 +8,456 @@ Functions for performing string manipulation.
[[sql-functions-string-ascii]]
==== `ASCII`
*Input*: `string`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
ASCII(string_exp<1>)
--------------------------------------------------
Returns the ASCII code value of the leftmost character of string_exp as an integer.
*Input*:
<1> string expression
*Output*: integer
.Description:
Returns the ASCII code value of the leftmost character of `string_exp` as an integer.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringAscii]
----
--------------------------------------------------
[[sql-functions-string-bit-length]]
==== `BIT_LENGTH`
*Input*: `string`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
BIT_LENGTH(string_exp<1>)
--------------------------------------------------
*Input*:
Returns the length in bits of the input.
<1> string expression
*Output*: integer
.Description:
Returns the length in bits of the `string_exp` input expression.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringBitLength]
----
--------------------------------------------------
[[sql-functions-string-char]]
==== `CHAR`
*Input*: `numeric`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
CHAR(code<1>)
--------------------------------------------------
*Input*:
<1> integer expression
*Output*: string
.Description:
Returns the character that has the ASCII code value specified by the numeric input. The value should be between 0 and 255; otherwise, the return value is data sourcedependent.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringChar]
----
--------------------------------------------------
[[sql-functions-string-char-length]]
==== `CHAR_LENGTH`
*Input*: `string`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
CHAR_LENGTH(string_exp<1>)
--------------------------------------------------
*Input*:
<1> string expression
*Output*: integer
.Description:
Returns the length in characters of the input, if the string expression is of a character data type; otherwise, returns the length in bytes of the string expression (the smallest integer not less than the number of bits divided by 8).
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringCharLength]
----
--------------------------------------------------
[[sql-functions-string-concat]]
==== `CONCAT`
*Input*: `string1`, `string2`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
CONCAT(string_exp1<1>,string_exp2<2>)
--------------------------------------------------
*Input*:
turns a character string that is the result of concatenating string1 to string2. If one of the string is `NULL`,
the other string will be returned.
<1> string expression
<2> string expression
*Output*: string
.Description:
Returns a character string that is the result of concatenating `string_exp1` to `string_exp2`. If one of the string is `NULL`, the other string will be returned.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringConcat]
----
--------------------------------------------------
[[sql-functions-string-insert]]
==== `INSERT`
*Input*: `string1`, `start`, `length`, `string2`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
INSERT(source<1>, start<2>, length<3>, replacement<4>)
--------------------------------------------------
*Input*:
Returns a string where length characters have been deleted from string1, beginning at start, and where string2 has been inserted into string1, beginning at start.
<1> string expression
<2> integer expression
<3> integer expression
<4> string expression
*Output*: string
.Description:
Returns a string where `length` characters have been deleted from `source`, beginning at `start`, and where `replacement` has been inserted into `source`, beginning at `start`.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringInsert]
----
--------------------------------------------------
[[sql-functions-string-lcase]]
==== `LCASE`
*Input*: `string`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
LCASE(string_exp<1>)
--------------------------------------------------
*Input*:
Returns a string equal to that in string, with all uppercase characters converted to lowercase.
<1> string expression
*Output*: string
.Description:
Returns a string equal to that in `string_exp`, with all uppercase characters converted to lowercase.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringLCase]
----
--------------------------------------------------
[[sql-functions-string-left]]
==== `LEFT`
*Input*: `string`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
LEFT(string_exp<1>, count<2>)
--------------------------------------------------
*Input*:
Returns the leftmost count characters of string.
<1> string expression
<2> integer expression
*Output*: string
.Description:
Returns the leftmost count characters of `string_exp`.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringLeft]
----
--------------------------------------------------
[[sql-functions-string-length]]
==== `LENGTH`
*Input*: `string`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
LENGTH(string_exp<1>)
--------------------------------------------------
*Input*:
Returns the number of characters in string, excluding trailing blanks.
<1> string expression
*Output*: integer
.Description:
Returns the number of characters in `string_exp`, excluding trailing blanks.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringLength]
----
--------------------------------------------------
[[sql-functions-string-locate]]
==== `LOCATE`
*Input*: `string1`, `string2`[, `start`]`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
LOCATE(pattern<1>, source<2>[, start]<3>)
--------------------------------------------------
*Input*:
Returns the starting position of the first occurrence of string1 within string2. The search for the first occurrence of string1 begins with the first character position in string2 unless the optional argument, start, is specified. If start is specified, the search begins with the character position indicated by the value of start. The first character position in string2 is indicated by the value 1. If string1 is not found within string2, the value 0 is returned.
<1> string expression
<2> string expression
<3> integer expression; optional
*Output*: integer
.Description:
Returns the starting position of the first occurrence of `pattern` within `source`. The search for the first occurrence of `pattern` begins with the first character position in `source` unless the optional argument, `start`, is specified. If `start` is specified, the search begins with the character position indicated by the value of `start`. The first character position in `source` is indicated by the value 1. If `pattern` is not found within `source`, the value 0 is returned.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringLocateWoStart]
----
--------------------------------------------------
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringLocateWithStart]
----
--------------------------------------------------
[[sql-functions-string-ltrim]]
==== `LTRIM`
*Input*: `string`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
LTRIM(string_exp<1>)
--------------------------------------------------
*Input*:
Returns the characters of string_exp, with leading blanks removed.
<1> string expression
*Output*: string
.Description:
Returns the characters of `string_exp`, with leading blanks removed.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringLTrim]
----
--------------------------------------------------
[[sql-functions-string-position]]
==== `POSITION`
*Input*: `string1`, `string2`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
POSITION(string_exp1<1>, string_exp2<2>)
--------------------------------------------------
*Input*:
Returns the position of the string1 in string2. The result is an exact numeric.
<1> string expression
<2> string expression
*Output*: integer
.Description:
Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringPosition]
----
--------------------------------------------------
[[sql-functions-string-repeat]]
==== `REPEAT`
*Input*: `string`, `count`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
REPEAT(string_exp<1>, count<2>)
--------------------------------------------------
*Input*:
Returns a character string composed of string1 repeated count times.
<1> string expression
<2> integer expression
*Output*: string
.Description:
Returns a character string composed of `string_exp` repeated `count` times.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringRepeat]
----
--------------------------------------------------
[[sql-functions-string-replace]]
==== `REPLACE`
*Input*: `string1`, `string2`, `string3`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
REPLACE(source<1>, pattern<2>, replacement<3>)
--------------------------------------------------
*Input*:
Search string1 for occurrences of string2, and replace with string3.
<1> string expression
<2> string expression
<3> string expression
*Output*: string
.Description:
Search `source` for occurrences of `pattern`, and replace with `replacement`.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringReplace]
----
--------------------------------------------------
[[sql-functions-string-right]]
==== `RIGHT`
*Input*: `string`, `count`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
RIGHT(string_exp<1>, count<2>)
--------------------------------------------------
*Input*:
Returns the rightmost count characters of string.
<1> string expression
<2> integer expression
*Output*: string
.Description:
Returns the rightmost count characters of `string_exp`.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringRight]
----
--------------------------------------------------
[[sql-functions-string-rtrim]]
==== `RTRIM`
*Input*: `string`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
RTRIM(string_exp<1>)
--------------------------------------------------
*Input*:
Returns the characters of string with trailing blanks removed.
<1> string expression
*Output*: string
.Description:
Returns the characters of `string_exp` with trailing blanks removed.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringRTrim]
----
--------------------------------------------------
[[sql-functions-string-space]]
==== `SPACE`
*Input*: `integer`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
SPACE(count<1>)
--------------------------------------------------
*Input*:
Returns a character string consisting of count spaces.
<1> integer expression
*Output*: string
.Description:
Returns a character string consisting of `count` spaces.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringSpace]
----
--------------------------------------------------
[[sql-functions-string-substring]]
==== `SUBSTRING`
*Input*: `string`, `start`, `length`, *Output*: `integer`
.Synopsis:
[source, sql]
--------------------------------------------------
SUBSTRING(source<1>, start<2>, length<3>)
--------------------------------------------------
*Input*:
Returns a character string that is derived from the string, beginning at the character position specified by `start` for `length` characters.
<1> string expression
<2> integer expression
<3> integer expression
*Output*: string
.Description:
Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringSubString]
----
--------------------------------------------------
[[sql-functions-string-ucase]]
==== `UCASE`
*Input*: `string`, *Output*: `string`
.Synopsis:
[source, sql]
--------------------------------------------------
UCASE(string_exp<1>)
--------------------------------------------------
*Input*:
<1> string expression
*Output*: string
.Description:
Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
["source","sql",subs="attributes,callouts,macros"]
----
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringUCase]
----
--------------------------------------------------

View File

@ -1126,6 +1126,222 @@ SELECT YEAR(CAST('2018-05-19T11:23:45Z' AS TIMESTAMP)) AS year;
// end::conversionStringToDateCast
;
///////////////////////////////
//
// Math
//
///////////////////////////////
mathInlineAbs
// tag::abs
SELECT ABS(-123.5), ABS(55);
ABS(-123.5) | ABS(55)
---------------+---------------
123.5 |55
// end::abs
;
mathInlineAcos
// tag::mathInlineAcos
SELECT ACOS(COS(PI())), PI();
ACOS(COS(PI)) | PI
-----------------+-----------------
3.141592653589793|3.141592653589793
// end::mathInlineAcos
;
mathInlineAsin
// tag::mathInlineAsin
SELECT ROUND(DEGREES(ASIN(0.7071067811865475))) AS "ASIN(0.707)", ROUND(SIN(RADIANS(45)), 3) AS "SIN(45)";
ASIN(0.707) | SIN(45)
---------------+---------------
45.0 |0.707
// end::mathInlineAsin
;
mathInlineAtan
// tag::mathInlineAtan
SELECT DEGREES(ATAN(TAN(RADIANS(90))));
DEGREES(ATAN(TAN(RADIANS(90))))
-------------------------------
90.0
// end::mathInlineAtan
;
mathInlineAtan2
// tag::mathInlineAtan2
SELECT ATAN2(5 * SIN(RADIANS(45)), 5 * COS(RADIANS(45))) AS "ATAN2(5*SIN(45), 5*COS(45))", RADIANS(45);
ATAN2(5*SIN(45), 5*COS(45))| RADIANS(45)
---------------------------+------------------
0.7853981633974483 |0.7853981633974483
// end::mathInlineAtan2
;
mathInlineCbrtWithNegativeValue
// tag::mathInlineCbrtWithNegativeValue
SELECT CBRT(-125.5);
CBRT(-125.5)
-------------------
-5.0066577974783435
// end::mathInlineCbrtWithNegativeValue
;
mathInlineCeiling
// tag::mathInlineCeiling
SELECT CEIL(125.01), CEILING(-125.99);
CEIL(125.01) | CEIL(-125.99)
---------------+---------------
126 |-125
// end::mathInlineCeiling
;
mathInlineCosine
// tag::mathInlineCosine
SELECT COS(RADIANS(180)), POWER(SIN(RADIANS(54)), 2) + POWER(COS(RADIANS(54)), 2) AS pythagorean_identity;
COS(RADIANS(180))|pythagorean_identity
-----------------+--------------------
-1.0 |1.0
// end::mathInlineCosine
;
mathInlineCosh
// tag::mathInlineCosh
SELECT COSH(5), (POWER(E(), 5) + POWER(E(), -5)) / 2 AS "(e^5 + e^-5)/2";
COSH(5) | (e^5 + e^-5)/2
-----------------+-----------------
74.20994852478785|74.20994852478783
// end::mathInlineCosh
;
mathInlineCotangent
// tag::mathInlineCotangent
SELECT COT(RADIANS(30)) AS "COT(30)", COS(RADIANS(30)) / SIN(RADIANS(30)) AS "COS(30)/SIN(30)";
COT(30) | COS(30)/SIN(30)
------------------+------------------
1.7320508075688774|1.7320508075688776
// end::mathInlineCotangent
;
mathInlineDegrees
// tag::mathInlineDegrees
SELECT DEGREES(PI() * 2), DEGREES(PI());
DEGREES(((PI) * 2))| DEGREES(PI)
-------------------+---------------
360.0 |180.0
// end::mathInlineDegrees
;
mathEulersNumber
// tag::mathEulersNumber
SELECT E(), CEIL(E());
E | CEIL(E)
-----------------+---------------
2.718281828459045|3
// end::mathEulersNumber
;
mathExpInline
// tag::mathExpInline
SELECT EXP(1), E(), EXP(2), E() * E();
EXP(1) | E | EXP(2) | ((E) * (E))
-----------------+-----------------+----------------+------------------
2.718281828459045|2.718281828459045|7.38905609893065|7.3890560989306495
// end::mathExpInline
;
mathExpm1Inline
// tag::mathExpm1Inline
SELECT E(), EXP(2), EXPM1(2);
E | EXP(2) | EXPM1(2)
-----------------+----------------+----------------
2.718281828459045|7.38905609893065|6.38905609893065
// end::mathExpm1Inline
;
mathInlineFloor
// tag::mathInlineFloor
SELECT FLOOR(125.01), FLOOR(-125.99);
FLOOR(125.01) |FLOOR(-125.99)
---------------+---------------
125 |-126
// end::mathInlineFloor
;
mathInlineLog
// tag::mathInlineLog
SELECT EXP(3), LOG(20.085536923187668);
EXP(3) |LOG(20.085536923187668)
------------------+-----------------------
20.085536923187668|3.0
// end::mathInlineLog
;
mathInlineLog10
// tag::mathInlineLog10
SELECT LOG10(5), LOG(5)/LOG(10);
LOG10(5) |((LOG(5)) / (LOG(10)))
------------------+----------------------
0.6989700043360189|0.6989700043360187
// end::mathInlineLog10
;
mathPINumber
// tag::mathPINumber
SELECT PI();
PI
-----------------
3.141592653589793
// end::mathPINumber
;
mathInlinePowerPositive
// tag::mathInlinePowerPositive
SELECT POWER(3, 2), POWER(3, 3);
POWER(3,2) | POWER(3,3)
---------------+---------------
9.0 |27.0
// end::mathInlinePowerPositive
;
mathInlinePowerNegative
// tag::mathInlinePowerNegative
SELECT POWER(5, -1), POWER(5, -2);
POWER(5,-1) | POWER(5,-2)
---------------+---------------
0.2 |0.04
// end::mathInlinePowerNegative
;
mathInlineRadians
// tag::mathInlineRadians
SELECT RADIANS(90), PI()/2;
RADIANS(90) | ((PI) / 2)
------------------+------------------
1.5707963267948966|1.5707963267948966
// end::mathInlineRadians
;
mathRoundWithNegativeParameter
// tag::mathRoundWithNegativeParameter
SELECT ROUND(-345.153, -1) AS rounded;
@ -1146,6 +1362,56 @@ SELECT ROUND(-345.153, 1) AS rounded;
// end::mathRoundWithPositiveParameter
;
mathInlineSign
// tag::mathInlineSign
SELECT SIGN(-123), SIGN(0), SIGN(415);
SIGN(-123) | SIGN(0) | SIGN(415)
---------------+---------------+---------------
-1 |0 |1
// end::mathInlineSign
;
mathInlineSine
// tag::mathInlineSine
SELECT SIN(RADIANS(90)), POWER(SIN(RADIANS(67)), 2) + POWER(COS(RADIANS(67)), 2) AS pythagorean_identity;
SIN(RADIANS(90))|pythagorean_identity
----------------+--------------------
1.0 |1.0
// end::mathInlineSine
;
mathInlineSinh
// tag::mathInlineSinh
SELECT SINH(5), (POWER(E(), 5) - POWER(E(), -5)) / 2 AS "(e^5 - e^-5)/2";
SINH(5) | (e^5 - e^-5)/2
-----------------+-----------------
74.20321057778875|74.20321057778874
// end::mathInlineSinh
;
mathInlineSqrt
// tag::mathInlineSqrt
SELECT SQRT(EXP(2)), E(), SQRT(25);
SQRT(EXP(2)) | E | SQRT(25)
-----------------+-----------------+---------------
2.718281828459045|2.718281828459045|5.0
// end::mathInlineSqrt
;
mathInlineTanget
// tag::mathInlineTanget
SELECT TAN(RADIANS(66)) AS "TAN(66)", SIN(RADIANS(66))/COS(RADIANS(66)) AS "SIN(66)/COS(66)=TAN(66)";
TAN(66) |SIN(66)/COS(66)=TAN(66)
------------------+-----------------------
2.2460367739042164|2.246036773904216
// end::mathInlineTanget
;
mathTruncateWithNegativeParameter
// tag::mathTruncateWithNegativeParameter
SELECT TRUNCATE(-345.153, -1) AS trimmed;
@ -1164,4 +1430,5 @@ SELECT TRUNCATE(-345.153, 1) AS trimmed;
---------------
-345.1
// end::mathTruncateWithPositiveParameter
;
;

View File

@ -3,86 +3,50 @@
//
mathAbs
// tag::abs
SELECT ABS(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::abs
mathACos
// tag::acos
SELECT ACOS(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::acos
mathASin
// tag::asin
SELECT ASIN(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::asin
mathATan
// tag::atan
SELECT ATAN(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::atan
//mathCbrt
//SELECT CBRT(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathCeil
// H2 returns CEIL as a double despite the value being an integer; we return a long as the other DBs
SELECT CAST(CEIL(emp_no) AS INT) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathCos
// tag::cos
SELECT COS(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::cos
mathCosh
// tag::cosh
SELECT COSH(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::cosh
mathCot
// tag::cot
SELECT COT(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::cot
mathDegrees
// tag::degrees
SELECT DEGREES(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::degrees
mathExp
// tag::exp
SELECT EXP(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::exp
mathExpm1
// tag::expm1
SELECT EXP(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::expm1
mathFloor
SELECT CAST(FLOOR(emp_no) AS INT) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathLog
// tag::log
SELECT LOG(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::log
mathLog10
// tag::log10
SELECT LOG10(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::log10
mathRadians
// tag::radians
SELECT RADIANS(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::radians
mathRound
SELECT CAST(ROUND(emp_no, 0) AS INT) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathSign
// tag::sign
SELECT SIGN(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::sign
mathSin
// tag::sin
SELECT SIN(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::sin
mathSinH
// tag::sinh
SELECT SINH(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::sinh
mathSqrt
// tag::sqrt
SELECT SQRT(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::sqrt
mathTan
// tag::tan
SELECT TAN(emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::tan
//
// Combined methods
@ -125,15 +89,11 @@ SELECT 5 + 2 * 3 / 2 % 2 AS c, PI() as e, first_name FROM "test_emp" WHERE emp_n
// binary functions
//
mathATan2
// tag::atan2
SELECT ATAN2(emp_no, emp_no) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::atan2
// tag::power
mathPowerPositive
SELECT POWER(emp_no, 2) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathPowerNegative
SELECT POWER(salary, -1) m, first_name FROM "test_emp" WHERE emp_no < 10010 ORDER BY emp_no;
// end::power
roundInline1
SELECT ROUND(-345.123, -2) AS rounded;