Skip to content

Commit 39c76b4

Browse files
authored
fix(postgresql): support binary/octal/hex integer literals (#61)
1 parent f75e297 commit 39c76b4

File tree

5 files changed

+3228
-3169
lines changed

5 files changed

+3228
-3169
lines changed

postgresql/PostgreSQLLexer.g4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,18 @@ Integral
25872587
: Digits
25882588
;
25892589

2590+
BinaryIntegral
2591+
: '0b' Digits
2592+
;
2593+
2594+
OctalIntegral
2595+
: '0o' Digits
2596+
;
2597+
2598+
HexadecimalIntegral
2599+
: '0x' Digits
2600+
;
2601+
25902602
NumericFail
25912603
: Digits '..'
25922604
{l.HandleNumericFail();}

postgresql/PostgreSQLParser.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4105,6 +4105,9 @@ fconst
41054105

41064106
iconst
41074107
: Integral
4108+
| BinaryIntegral
4109+
| OctalIntegral
4110+
| HexadecimalIntegral
41084111
;
41094112

41104113
sconst

postgresql/examples/numeric.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,9 @@ SELECT pg_lsn(18446744073709551615::numeric);
13161316
SELECT pg_lsn(-1::numeric);
13171317
SELECT pg_lsn(18446744073709551616::numeric);
13181318
SELECT pg_lsn('NaN'::numeric);
1319+
1320+
--
1321+
-- Tests for binary/octal/hex integer literals
1322+
--
1323+
SELECT abs(0b10), abs(0B10), abs(0x10), abs(0X10), abs(0o10), abs(0O10),
1324+
('{1}'::int[])[0b01], 1::char(0o01), (array[1])[0x01];

0 commit comments

Comments
 (0)