Skip to main content

Categories: String

LPAD

Left pads a string with spaces or specified characters to reach the number of chracters specified as a parameter.

Syntax

LPAD(base_expression varchar, length int64) → varchar

  • base_expression: The expression to pad.
  • length: The number of characters to return.

Examples

LPAD example
SELECT LPAD('parameter', 11)
-- parameter
LPAD example
SELECT LPAD('engineering', 6)
-- engine

LPAD(base_expression varchar, length int64 [, pad_expression varchar]) → varchar

  • base_expression: The expression to pad.
  • length: The number of characters to return.
  • pad_expression (optional): Characters to pad the base_expression with.

Examples

LPAD example
select LPAD('parameter', 11, '-')
-- --parameter

Usage Notes

If pad_expression is not specified, then the base_expresion will be padded with spaces. If the length of parameter is less than the length of the base_expression, the base_expression will be truncated to the length. If the length parameter + the length of the base_expression is less than the length of the base_expression + the length of the pad_expression, only the subset of the characters from the pad_expression required to fill the length will be appended to the base_expression.