Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.73 KB

File metadata and controls

49 lines (36 loc) · 1.73 KB
description
Right pads a string with spaces or specified characters to reach the number of characters specified as a parameter.

RPAD

Syntax

RPAD(base_expression varchar, length int64, pad_expression varchar) → varchar

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

Examples

{% code title="RPAD example" %}

SELECT RPAD('spice', 9, '!')
-- spice!!!

{% endcode %}

{% code title="RPAD example" %}

SELECT RPAD('base_', 9, 'expression')
-- base_expr

{% endcode %}

RPAD(base_expression varchar, length int64) → varchar

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

Examples

{% code title="RPAD example" %}

SELECT RPAD('spice', 9)
-- spice    

{% endcode %}

Usage Notes

If pad_expression is not specified, then the base_expression will be padded with spaces. If length is less than the length of the base_expression, the base_expression will be truncated to the length. If the length + 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.