Function
substring — slice strings with SQL substring function
Synopsis
substring(s: string [ FROM start: number ] [ FOR len: number ]) -> string
Description
The substring function returns a slice of a string using
the anachronistic SQL syntax which includes the FROM and FOR keywords
inside of the call arguments. The function returns a string of length len
comprising the unicode code points starting at offset start.
Indexing is 0-based by default but can be 1-based by the use of a pragma as with generalized indexing.
Tip
This function is implemented for backward compatibility with SQL. Slice expressions should be used instead and are best practice.
Examples
Simple substring call from in a SQL operator
# spq
SELECT SUBSTRING(this FROM 3 FOR 7) AS s
# input
" = SuperDB = "
# expected output
{s:"SuperDB"}
1-based indexing
# spq
pragma index_base = 1
SELECT SUBSTRING(this FROM 4 FOR 7) AS s
# input
" = SuperDB = "
# expected output
{s:"SuperDB"}
The length parameter is optional
# spq
SELECT SUBSTRING(this FROM 3) AS s
# input
" = SuperDB = "
# expected output
{s:"SuperDB = "}