PRINTF

Format a string using printf-style placeholders (alias for FORMAT_STRING).

Category: miscReturns: STRINGDialect: Standard

Syntax

PRINTF(fmt, args...)

Description

## 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.

Parameters

NameTypeDescription
fmtSpecifies the format string. Supported placeholders include %s (string), %d (integer), %f (floating-point), and %.Nf (fixed precision float).
argsSpecifies the positional arguments substituted into the placeholders, in order.

Examples

-- 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);

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →