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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

format(FORMAT, ...)  |  printf(FORMAT, ...)

Parameters

ParameterDescription
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

Format pricesTry it yourself
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
Padding and thousandsTry it yourself
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

VersionChange
SQLite 3.8.3Added
SQLite 3.38.0Renamed to format(); printf() still works as an alias.

In other languages

Was this page helpful?