RIGHT()
All functions > STRING > RIGHT()
Returns the last n characters of the string (or the full string when n is greater than its length).
Signatures
Returns: Trailing substring
RIGHT(string: VARCHAR, n: BIGINT) → VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | Source string |
n | BIGINT | Yes | Number of characters to take from the end |
Notes
- Shorthand for taking a suffix; for a 1-indexed start and length, use
SUBSTRinstead - For
nlarger than the string length, the whole string is returned; forn = 0, the result is'' - If
STRINGorNis NULL, the result is NULL (useNULL(VARCHAR)/NULL(BIGINT); bareNULLfails inference)
Examples
FeatureQL
SELECT
f1 := RIGHT('abcdef', 3), -- Last three characters
f2 := RIGHT('abcdef', 3), -- Matches SUBSTR for the same suffix
f3 := RIGHT('hi', 10), -- n longer than string
f4 := RIGHT('x', 0), -- Zero length
f5 := RIGHT('x', NULL(BIGINT)) -- NULL count yields NULL
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR |
|---|---|---|---|---|
| def | def | hi | (empty) | NULL |
On this page