SQLite has introduced the FORMAT()
function, which can be used to format strings.
More precisely, it has actually just renamed its SQL PRINTF()
function to FORMAT()
. The reason is for better compatibility with other DBMSs. The original PRINTF()
name is retained as an alias for backwards compatibility.
The FORMAT()
function (or its naming) was introduced in SQLite 3.38.0, which was released on 22 February 2022.
Example
Here’s an example to demonstrate:
SELECT
PRINTF("%,d", 123456789) AS PRINTF,
FORMAT("%,d", 123456789) AS FORMAT;
Result:
PRINTF FORMAT ----------- ----------- 123,456,789 123,456,789
We can see that FORMAT()
is used in the same way that PRINTF()
is used, and its result is the same.
See SQLite’s documentation for the FORMAT()
function for an overview of the function.
Also see SQLite’s documentation for PRINTF()
for a detailed explanation.