Tabular IQ
Back to Function Index

LPAD()

Overview

LPAD() adds the first character from the specified list to the left side of a string until it reaches the desired length. If no characters are specified in the list, LPAD() adds spaces to the left side. This function is useful for string formatting, alignment, and padding. LPAD() is similar to RPAD(), which adds characters to the right side of a string.

Function Format

LPAD(string, length [, list])

Return Value

LPAD() returns a character string

Examples


LPAD("APPLES", 10, ".") = "....APPLES"    (padded with dots)
LPAD("APPLES", 10) = "    APPLES"         (padded with spaces)
LPAD("APPLES", 3) = "APP"                 (truncated to length)
LPAD("123", 5, "0") = "00123"             (zero-padded number)
LPAD("", 5, "*") = "*****"               (empty string padded)
LPAD(NULL, 5, "*") = NULL                 (NULL input)
LPAD("ABC", 5, "12") = "11ABC"           (uses first character from list)

Notes

  • Important behaviors:
    • If length is less than string length, string is truncated
    • If no list is specified, spaces are used for padding
    • Only the first character from the list is used
    • Returns NULL for NULL input
    • Padding is added to the left side only
  • Common use cases include:
    • String alignment
    • Number formatting
    • Fixed-width formatting
    • Data presentation
    • Report generation
  • The function can be used with:
    • String literals
    • String columns
    • String expressions
    • String functions
  • This function is often used in combination with other string functions like RPAD(), TRIM(), and CONCAT() for more complex string manipulations.
  • For right-side padding, use the RPAD() function instead.

See Also