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
ParameterTypeRequiredDescription
stringVARCHARYesSource string
nBIGINTYesNumber of characters to take from the end

Notes

  • Shorthand for taking a suffix; for a 1-indexed start and length, use SUBSTR instead
  • For n larger than the string length, the whole string is returned; for n = 0, the result is ''
  • If STRING or N is NULL, the result is NULL (use NULL(VARCHAR) / NULL(BIGINT); bare NULL fails 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 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHAR
defdefhi(empty)NULL

Last update at: 2026/05/26 17:22:09