SQLite 3 reference · String Functions
SQLite FORMAT() Function
Build a string from a template with printf-style placeholders such as %s, %d, %.2f and %,d. printf() is the old name.
SQLite 3 Since 3.8.3
Syntax
format(FORMAT, ...) | printf(FORMAT, ...)
Parameters
| Parameter | Description |
|---|---|
FORMAT |
The template: %s text, %d integer, %.2f decimal, %5s padded, %,d thousands separators, %q SQL-quoted, %% a percent sign. |
... |
Values for the placeholders. |
Return value
The formatted text.
Examples
SELECT format('%s costs $%.2f', name, price) AS line
FROM products
LIMIT 3;
Output
line SQL for Beginners costs $29.99 Clean Code costs $37.50 The Pragmatic Programmer costs $42.00
SELECT format('%05d', 42) AS padded,
format('%,d', 1234567) AS grouped,
format('%-6s|', 'ab') AS left_aligned;
Output
padded | grouped | left_aligned 00042 | 1,234,567 | ab |
Version history
| Version | Change |
|---|---|
| SQLite 3.8.3 | Added |
| SQLite 3.38.0 | Renamed to format(); printf() still works as an alias. |
In other languages
Related
CONCAT()· Join any number of values into one string. Unlike ||, NULL arguments are skipped instead of making the result NULL.ROUND()· Round a number to a given number of decimal places (0 by default). Halves round away from zero.- SQL String Functions · tutorial