LPAD()

All functions > STRING > LPAD()

Returns the string padded on the left to a specified length with a padding string.

Signatures

Returns: String padded on the left to the specified length

LPAD(string: VARCHAR, length: BIGINT, padding: VARCHAR) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesString to pad
lengthBIGINTYesTarget length for the result
paddingVARCHARYesString to use for padding

Notes

  • If the input is already longer than the target length, the result is truncated on the right
  • The padding string is repeated as needed; if it is longer than the gap, only the required portion is used
  • If any argument is NULL, the result is NULL (use NULL(VARCHAR) / NULL(BIGINT); bare NULL fails inference)

Examples

FeatureQL
SELECT
    f1 := LPAD('hello', 10, '-'), -- Pad with dashes
    f2 := LPAD('123', 7, '0'), -- Zero padding
    f3 := LPAD('AB', 6, 'XY'), -- Multi-character padding
    f4 := LPAD('hello', 3, '-'), -- Truncation when too long
    f5 := LPAD('test', 4, ' '), -- No padding needed
    f6 := LPAD(NULL(VARCHAR), 5, 'x') -- NULL string yields NULL
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHARf6 VARCHAR
-----hello0000123XYXYABheltestNULL

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