T662, “Underscores in numeric literals”


BigQueryDb2 (LUW)DerbyH2MariaDBMySQLOracle DBPostgreSQLSQL ServerSQLite2005200720092011201320152017201920212023⚡ 3.5.7 - 3.50.0a⊘ 2008R2 - 2022⚠ 16 - 17cd⊘ 8.3 - 15⊘ 11gR1 - 23.9⚡ 5.0 - 9.4.0a⚡ 5.1 - 12.0.2a⚠ 2.2.220 - 2.3.232b⊘ 1.4.192 - 2.1.214⊘ 10.15.1.3 - 10.17.1.0⊘ 9.7 - 12.1.2⊘ 2.0
  1. Wrong results in cast
  2. Only in literals, not in cast
  3. Limited support in cast
  4. Also for binary, octal and hexadecimal notation

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).

BigQuery 2025-09-02Db2 (LUW) 12.1.2Derby 10.17.1.0H2 2.3.232MariaDB 12.0.2aaaMySQL 9.4.0aaaOracle DB 23.9PostgreSQL 17SQL Server 2022SQLite 3.50.0aaa1_0001_000.000_11_2.3_4e1_0CAST('1_000' AS …)CAST('1_000.000_1' AS …)CAST('1_2.3_4e1_0' AS …)
  1. Doesn’t fail, but returns the wrong result. E.g. just the part before the first underscore
Optional Features

Normative References

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.

About the Author

Photo of Markus Winand

Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.

Buy the Book

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy now!
(paperback and/or PDF)

Paperback also available at Amazon.com.

Hire Markus

Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »

Footnotes

  1. ISO/IEC 9075-2:2023 §6.13 GR 8b and ISO/IEC 9075-2:2023 §6.13 GR 9b

Connect with Markus Winand

Subscribe mailinglistsSubscribe the RSS feedMarkus Winand on LinkedInMarkus Winand on XINGMarkus Winand on TwitterMarkus Winand on Bluesky
Copyright 2015-2025 Markus Winand. All righs reserved.
Legal | Contact | NO WARRANTY | Trademarks | Privacy and GDPR