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
-- Last three characters
f1 := RIGHT('abcdef', 3),
-- Matches SUBSTR for the same suffix
f2 := RIGHT('abcdef', 3),
-- n longer than string
f3 := RIGHT('hi', 10),
-- Zero length
f4 := RIGHT('x', 0),
-- NULL count yields NULL
f5 := RIGHT('x', NULL(BIGINT))
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR |
|---|---|---|---|---|
| def | def | hi | (empty) | NULL |
On this page