The FORMAT function returns a string formatted using the specified format string and parameters. The formatting rules follow the fmt format specification.
FORMAT(<format>, <args>[, ...])
| Parameter | Description |
|---|---|
<format> | Format string containing format placeholders. Type: VARCHAR |
<args> | Parameters to be formatted (can be multiple). Type: ANY |
Returns VARCHAR type, representing the result formatted according to the format string.
Special cases:
{} as placeholder{0}, {1}) and named parametersSELECT format('{:.2}', pi());
+-----------------------+ | format('{:.2}', pi()) | +-----------------------+ | 3.1 | +-----------------------+
SELECT format('{0}-{1}', 'hello', 'world');
+-------------------------------------+ | format('{0}-{1}', 'hello', 'world') | +-------------------------------------+ | hello-world | +-------------------------------------+
SELECT format('{:>10}', 123);
+-----------------------+ | format('{:>10}', 123) | +-----------------------+ | 123 | +-----------------------+
SELECT format('{:.2}', NULL);
+-----------------------+ | format('{:.2}', NULL) | +-----------------------+ | NULL | +-----------------------+
SELECT format('{0}-{1}', 'ṭṛṭṛ', 'ṭṛ');
+---------------------------------------------+ | format('{0}-{1}', 'ṭṛṭṛ', 'ṭṛ') | +---------------------------------------------+ | ṭṛṭṛ-ṭṛ | +---------------------------------------------+