SUBSTRING
Extracts a substring starting from a specified point within the given string.
This is an alias for the SUBSTR
function.
Syntax
SUBSTRING(STRING, START [, LENGTH])
Arguments
STRING
STRING
Type: string
The string to extract a substring from.
START
START
Type: integer
The starting index of the substring.
Positions start with 1
. A negative starting position is interpreted as being relative to the end of the string.
LENGTH
LENGTH
Type: integer
(Optional) The length of the substring.
If omitted, the rest of the string after the starting position START
is returned.
Returns
Type: string
Returns a substring from STRING
of length LENGTH
from the starting position START
.
Examples
Hello World
1
5
Hello
Hello World
0
4
''
Hello World
-5
5
World
Hello World
12
4
''
Hello World
-12
4
''
Hello World
2
3
ell
Hello World
3
-2
''
Hello World
2
14
ello World
Hello World
2
ello World
Hello World
-3
2
rl
null
-3
2
null
Transformation job example
SQL
CREATE JOB function_operator_example
ADD_MISSING_COLUMNS = true
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data
MAP_COLUMNS_BY_NAME
SELECT
orderid,
SUBSTRING(orderid, 1, 5) AS orderid_substring
FROM default_glue_catalog.upsolver_samples.orders_raw_data
WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
LIMIT 3;
Query result
yKib3twExs
yKib3
g7uXq8bySD
g7uXq
NQ2xWzj1EV
NQ2xW
Last updated