Skip to content

PostgreSQL: Parse hexadecimal, octal and binary integer literals - #2758

Merged
LucaCappelletti94 merged 2 commits into
mainfrom
upstream/postgres-integer-literals
Oct 29, 2026
Merged

LucaCappelletti94 merged 2 commits into
mainfrom
upstream/postgres-integer-literals

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Since version 16, PostgreSQL reads 0x1F, 0X1F, 0o17 and 0b101 as integers, with underscores allowed as in 0x_FF_FF (docs). PostgreSqlDialect turned 0x1F into Value::HexStringLiteral("1F"), the same value as the bit string X'1F', and split the other spellings into a zero followed by an alias, so SELECT 0o17 came back as SELECT 0 AS o17.

The new Dialect::supports_non_decimal_integer_literals, enabled for PostgreSQL, makes the tokenizer read these prefixes into a Number token that keeps the literal as written, so it round-trips. With the bigdecimal feature the value is stored as its decimal, the same way 10_000 already is. Other dialects, GenericDialect included, keep 0x as a hex string, as MySQL and SQL Server read it.

@LucaCappelletti94 LucaCappelletti94 added bug Something isn't working PostgreSQL labels Oct 28, 2026
@codecov-commenter

codecov-commenter commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.52%. Comparing base (a9c0767) to head (81b1cfa).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2758      +/-   ##
==========================================
+ Coverage   82.48%   82.52%   +0.04%     
==========================================
  Files          42       42              
  Lines       35468    35533      +65     
  Branches    35468    35533      +65     
==========================================
+ Hits        29255    29323      +68     
+ Misses       2676     2675       -1     
+ Partials     3537     3535       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/postgres-integer-literals branch from d63b0a1 to 638ba57 Compare October 28, 2026 20:12

@s5dsn-eqee s5dsn-eqee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/postgres-integer-literals branch from 638ba57 to 81b1cfa Compare October 29, 2026 11:55
@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

Thanks @s5dsn-eqee for the review, I will be merging this now.

cc @alamb

@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit b22bf61 Oct 29, 2026
10 checks passed
@alamb
alamb deleted the upstream/postgres-integer-literals branch October 29, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants