Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Substring.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
# Keyword `SUBSTRING`

AlaSQL supports ```SUBSTRING(string, start, length)``` function:

```string```: The string you want to slice.

```start```: Where the substring should start. Positive value counts from left. First character is ```1```. Zero and negative values count from right where ```0``` is the last character.

```length```: How many characters shall the substring have. If ```length``` is left out or larger than the rest of the ```string```, then ```SUBSTRING``` returns all remaining characters.

## Examples

```sql
SELECT SUBSTRING('abc',1)
SELECT SUBSTRING('abcd',1)
-- returns 'abcd'
SELECT SUBSTRING('abcd',3)
-- returns 'cd'
SELECT SUBSTRING('abcd',1,2)
-- returns 'ab'
SELECT SUBSTRING('abcd',2,2)
-- returns 'bc'
SELECT SUBSTRING('abcd',2,4)
-- returns 'bcd'
SELECT SUBSTRING('abcd',0)
-- returns 'd'
SELECT SUBSTRING('abcd',-1)
-- returns 'cd'
SELECT SUBSTRING('abcd',-5,3)
-- returns 'abc'
```