lpad()

Creates a string of a given length by inserting padding characters to the left of the string. If the argument is null, it returns 0, and if it receives a value other than the string, it evaluates the value after converting it to a string.

Syntax

lpad(STR_EXPR, OUTPUT_LENGTH, [PADDING_EXPR])
Required Parameters
STR_EXPR
String expression

OUTPUT_LENGTH Expression to specify the length of the result string after padding If the STR_EXPR value is longer than OUTPUT_LENGTH, the function cuts the string according to OUTPUT_LENGTH and returns it.

Optional Parameters
PADDING_EXPR
Expression to specify the padding character (default: whitespace).

Usage

json "{}" | eval lpadded=lpad("string", 10) => "     string"

json "{}" | eval lpadded=lpad("string", 10, "p") => "ppppstring"

json "{}" | eval lpadded=lpad("string", 10, "pad") => "padpstring"

json "{}" | eval lpadded=lpad("string", 3, "pad") => "str"

json "{}" | eval lpadded=lpad("string", null, "pad") => null

json "{}" | eval lpadded=lpad("string", 3, null) => null