Conversion

FORMAT

DuckDBDuckDB

Format string dengan placeholder menggunakan {} syntax. Lebih modern dari PRINTF.

Tipe hasil: VARCHARDiperbarui: 6 Jan 2026

Syntax

SQL
FORMAT(format_string, arg1, arg2, ...)

Parameter

format_stringVARCHARwajib

Format string dengan {} placeholders

arg1, arg2, ...ANYwajib

Nilai untuk mengisi placeholders

Contoh Penggunaan

Basic Format

SQL
1SELECT FORMAT('Hello {}, you have {} items', 'John', 5);

Sequential placeholder replacement.

Hasil
Hello John, you have 5 items

Positional Arguments

SQL
1SELECT FORMAT('{1} said hello to {0}', 'Bob', 'Alice');

Menggunakan index untuk reorder.

Hasil
Alice said hello to Bob

Number Formatting

SQL
1SELECT
2 FORMAT('Price: {:,.2f}', 1234567.89) AS price,
3 FORMAT('Change: {:+.1%}', 0.156) AS percent;

Format numbers dengan specifiers.

Hasil
Price: 1,234,567.89 | Change: +15.6%

Build Dynamic Message

SQL
1SELECT FORMAT(
2 'Order #{}: {} x {} = {}',
3 order_id,
4 quantity,
5 product_name,
6 FORMAT('{:,.2f}', total)
7) AS order_summary
8FROM orders;

Build readable order summary.