Waiting for PostgreSQL 16 – Allow underscores in integer and numeric constants.

On 4th of February 2023, Dean Rasheed committed patch:

Allow underscores in integer and numeric constants.
 
This allows underscores to be used in integer and numeric literals,
and their corresponding type input functions, for visual grouping.
For example:
 
    1_500_000_000
    3.14159_26535_89793
    0xffff_ffff
    0b_1001_0001
 
A single underscore is allowed between any 2 digits, or immediately
after the base prefix indicator of non-decimal integers, per SQL:202x
draft.
 
Peter Eisentraut and Dean Rasheed
 
Discussion: https://postgr.es/m/84aae844-dc55-a4be-86d9-4f0fa405cc97%40enterprisedb.com

Description seems pretty clear, so let's just see how it works:

=$ SELECT 1 + 1_000;
 ?COLUMN? 
----------
     1001
(1 ROW)
 
=$ SELECT 1_2 + 0x2_1;
 ?COLUMN? 
----------
       45
(1 ROW)

This is not a world shattering change, but it's for anyone that had to work with long numbers it will be nice addition, helping with readability of the queries.

Thanks to all involved.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.