Format a string using printf-style placeholders (alias for FORMAT_STRING).
PRINTF(fmt, args...)
## Overview Formats a string by substituting positional arguments into printf-style placeholders. PRINTF is a PG-compat alias for FORMAT_STRING; both have identical semantics. ## Behavior - Returns NULL if the format string is NULL. - NULL argument values are rendered as the literal text `null`. - Supported placeholders include %s, %d, %f, %.Nf, %x, and %%. - Deterministic with respect to its inputs; side effect free. ## Compatibility - PG-compat alias for FORMAT_STRING.
| Name | Type | Description |
|---|---|---|
fmt | Specifies the format string. Supported placeholders include %s (string), %d (integer), %f (floating-point), and %.Nf (fixed precision float). | |
args | Specifies the positional arguments substituted into the placeholders, in order. |
-- Simple substitution
SELECT PRINTF('Hello, %s!', 'world'); -- 'Hello, world!'
-- Integer formatting
SELECT PRINTF('Total: %d items', 42); -- 'Total: 42 items'
-- Float with precision and rounding
SELECT PRINTF('Price: $%.2f', 9.999); -- 'Price: $10.00'
-- Compose a report header
SELECT PRINTF('%s ordered %d units at $%.2f', 'Alice', 5, 9.99);