Extract a substring

Syntax

SUBSTRING(…string-expr…, …int-expr…, …int-expr…)

Typing

STRING, int, int -> STRING

Description

The first operand is the original string, and the two others are positions in that string where the substring starts and stops (with the usual convention that start is inclusive and stop is exclusive).

If one of the position is negative then it is meant to be relative to the end of the string.

Examples

expression evaluates to
SUBSTRING("foobar", 2, 4) "ob"
SUBSTRING("foobar", -2, 6) "ar"
SUBSTRING("foobar", -4, -2) "ob"
SUBSTRING("foobar", 20, 40) ""
SUBSTRING("foobar", -20, -40) ""