# lpad, rpad

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/string/pad)

Pads a string on the left or right to a specified character length.

## Syntax

```scopeql
lpad(<string>, width => <width> [, pad => <pad>])
rpad(<string>, width => <width> [, pad => <pad>])
```

## Arguments

| Argument   | Type     | Description                                                                      |
| ---------- | -------- | -------------------------------------------------------------------------------- |
| `<string>` | `string` | String to pad.                                                                   |
| `width`    | `int`    | Constant. Non-negative target length in Unicode characters. Must not be NULL.    |
| `pad`      | `string` | Optional constant; defaults to `' '`. Nonempty padding string. Must not be NULL. |

## Returns

Returns `string`.

* If the input is shorter than `width`, repeats `pad` and cuts off any excess padding.
* If the input is longer than `width`, keeps its first `width` characters.
* A width of 0 returns an empty string.
* A NULL input returns NULL.

## Examples

Pad store codes on the left and status labels on the right. Brackets make the right padding visible.

```scopeql
VALUES ('7', 'paid'), ('42', 'pending')
SELECT $0 AS store_code, $1 AS status
SELECT
    lpad(store_code, width => 4, pad => '0') AS export_store,
    '[' || rpad(status, width => 8) || ']' AS export_status
```

```text
+--------------+---------------+
| export_store | export_status |
+--------------+---------------+
| 0007         | [paid    ]    |
| 0042         | [pending ]    |
+--------------+---------------+
```
