String & Binary Functions (Matching/Comparison)
Returns a leftmost substring of its input. LEFT(STR,N) is equivalent to SUBSTR(STR,1,N).
LEFT( <string_expr> , <length_expr> )
This must be a
The length should be an expression that evaluates to an integer. It should specify:
The number of UTF-8 characters to return if the input is
The number of bytes to return if the input is
The data type of the returned value is the same as the data type of the input value (
Collation applies to
VARCHAR inputs. Collation does not apply if the input data type of the first parameter is
Although collation is accepted syntactically, collations have no impact on processing. For example, languages with two-character and three-character letters (e.g. “dzs” in Hungarian, “ch” in Czech) still count those as two or three characters (not one character) for the length argument.
However, the returned value retains the collation specification of the first argument. This might be useful if the returned value is passed to another function as part of nested function calls.
SELECT LEFT('ABCDEFG', 3); -------------------+ LEFT('ABCDEF', 3) | -------------------+ ABC | -------------------+