CYBERTEC PostgreSQL Logo

Underscores in numeric constants in PostgreSQL 16

04.2023 / Category: , / Tags: |

SQL and numeric constants

NEW in PostgreSQL 16 - support for underscores in integer and numeric constants! I already wrote about support for different notations in the upcoming PostgreSQL 16. This new major version also implements the SQL:202x standard (draft), allowing you to use underscore separators for integers and numeric constants.

Using underscore separators in integer and numeric constants makes the numbers more readable and easier to understand. For example, instead of writing 1000000000, you can write 1_000_000_000, which makes it easier to see that the number represents a billion. This is especially useful in large or complex numbers, where it can be difficult to identify the value of each digit. The use of underscores in this way is a convention used in many programming languages.

What new numeric constants notation will PostgreSQL 16 have?

Dean Rasheed and Peter Eisentraut implemented a patch which allows underscores in integer and numeric constants.
The commit message is:

Earlier in my tweet I proposed to use exponential notation in blog posts to ease the perception.

You are currently viewing a placeholder content from X. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.

More Information

Now we can use the underscores as well to nicely format our huge numbers:

But please remember that leading, trailing and double underscores will produce an error:

tl;dr

PostgreSQL 16 will support hexadecimal, octal, and binary integer literals as 0x, 0o, and 0b prefixes and underscore as a separator. These notations make it easier to read and understand code, interact with data stored in memory, and represent larger numbers more concisely. Check out out the "what's new" post series to know more about upcoming PostgreSQL versions.


In order to receive regular updates on important changes in PostgreSQL, subscribe to our newsletter, or follow us on Twitter, Facebook, or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *

CYBERTEC Logo white
Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2024
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram