format()

Formats a string using the fmt syntax.

Arguments & returns

format(format, …)

Scalar
Overload link format … Varargs Returns
#01 VARCHAR ANY VARCHAR

… accepts a variable number of arguments of the type shown.

Example

format example
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example · Run to view results.

In other engines

MySQLformat()

SELECT FORMAT(12332.1, 4)
In DuckDB
SELECT FORMAT('{:,.4f}', 12332.1)

SQLGlot example ↗

Trinoformat()

SELECT FORMAT('%s', 123)
In DuckDB
SELECT FORMAT('{}', 123)

SQLGlot example ↗

Used in larger rewrites 1

These examples use format as one part of a larger SQL translation.

Snowflakeuuid_string()

UUID_STRING('fe971b24-9572-4005-b22f-351e9c09274d', 'foo')
In DuckDB
(SELECT LOWER(SUBSTRING(h, 1, 8) || '-' || SUBSTRING(h, 9, 4) || '-' || '5' || SUBSTRING(h, 14, 3) || '-' || FORMAT('{:02x}', CAST('0x' || SUBSTRING(h, 17, 2) AS INT) & 63 | 128) || SUBSTRING(h, 19, 2) || '-' || SUBSTRING(h, 21, 12)) FROM (SELECT SUBSTRING(SHA1(UNHEX(REPLACE('fe971b24-9572-4005-b22f-351e9c09274d', '-', '')) || ENCODE('foo')), 1, 32) AS h))

SQLGlot example ↗