Skip to content

postgres parser: multiple or trailing underscores should error #2421

Description

@Jefffrey

We can use underscores in numbers, however if we have more than one in succession 10__00 or trailing 10_00_ this should error according to postgres:

postgres=# select version();
                                                         version
--------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 18.2 (Debian 18.2-1.pgdg13+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
(1 row)

postgres=# select 10__00;
ERROR:  trailing junk after numeric literal at or near "10__00"
LINE 1: select 10__00;
               ^
postgres=# select 10_00_;
ERROR:  trailing junk after numeric literal at or near "10_00_"
LINE 1: select 10_00_;
               ^
postgres=# select 10_00;
 ?column?
----------
     1000
(1 row)

This seems to currently be accepted:

// tests/sqlparser_postgres.rs

#[test]
fn parse_incorrect_underscores() {
    let sql = "SELECT 10_00";
    let result = pg().parse_sql_statements(sql);
    assert!(result.is_err());

    let sql = "SELECT 10_00_";
    let result = pg().parse_sql_statements(sql);
    assert!(result.is_err());
}
  • test fails since both of the statements parse successfully

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions