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
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to pad |
length | BIGINT | Yes | Target length for the result |
padding | VARCHAR | Yes | String 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); bareNULLfails inference)
Examples
FeatureQL
SELECT
-- Pad with dashes
f1 := LPAD('hello', 10, '-'),
-- Zero padding
f2 := LPAD('123', 7, '0'),
-- Multi-character padding
f3 := LPAD('AB', 6, 'XY'),
-- Truncation when too long
f4 := LPAD('hello', 3, '-'),
-- No padding needed
f5 := LPAD('test', 4, ' '),
-- NULL string yields NULL
f6 := LPAD(NULL(VARCHAR), 5, 'x')
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR | f6 VARCHAR |
|---|---|---|---|---|---|
| -----hello | 0000123 | XYXYAB | hel | test | NULL |
On this page