cast
cast
cast
The SQL standard allows implementations to ignore underscore characters (_
) inside numbers that are written directly into the SQL statement (literals). This can be used to improve the readability of numbers.
SELECT 1_000_000
, 0.000_001
, 1_2.3_4e5_6
FROM …
Underscores are allowed in all types of numeric literals: Integers, decimals and in the exponential (“scientific”) notation. If the system supports binary, octal and hexadecimal numbers, then the underscore is also allowed there. However, underscores are only allowed between digits (of the respective numeral system) and there is only one underscore allowed between two digits. Otherwise, they may appear everywhere—they are not restricted to groups of three digits.
The literal syntax of SQL is also used when casting a character string to numeric types.0 Consequently, underscores are also allowed in expressions such as cast('1_000' as integer)
.
The underscore (_
) as grouping separator in numbers is defined in ISO/IEC 9075-2:2023 as the optional feature T662, “Underscores in numeric literals”. It first appeared in the 2023 edition.
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-sql.com on your radar.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »
ISO/IEC 9075-2:2023 §6.13 GR 8b and ISO/IEC 9075-2:2023 §6.13 GR 9b