LPAD
Functions › Text › Change a string
Pads a string on the left to a given length, or cuts it to that length.
Syntax
LPAD( <string>, <length> [, <fill> ] )
Arguments
| Argument | Description |
|---|---|
<string> | The text to pad. |
<length> | The length of the result, in characters. An integer. |
<fill> | Optional. The text to pad with, repeated as needed. A space when left out. |
Returns
Text. NULL when any argument is NULL.
Usage notes
- When
<string>is already longer than<length>, the result is its first<length>characters:LPAD('12345', 3, '0')is123. - A
<length>of 0 or less gives an empty string. - An empty
<fill>returns<string>unchanged. - A
<length>that is not an integer is an error. - It always runs after the rows are read, never in the data store.
Examples
SELECT i.number, LPAD(i.number, 6, '0') AS padded FROM data.invoices i
| number | padded |
|---|---|
| 412 | 000412 |
| 10020 | 010020 |