digoal
2023-01-25
PostgreSQL , PolarDB , hexadecimal, octal, and binary integer literals
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=6fcda9aba8
Non-decimal integer literals
Add support for hexadecimal, octal, and binary integer literals:
0x42F
0o273
0b100101
per SQL:202x draft.
This adds support in the lexer as well as in the integer type input
functions.
Add non-decimal integer support to type numeric.
author Dean Rasheed <dean.a.rasheed@gmail.com>
Mon, 23 Jan 2023 19:21:22 +0000 (19:21 +0000)
committer Dean Rasheed <dean.a.rasheed@gmail.com>
Mon, 23 Jan 2023 19:21:22 +0000 (19:21 +0000)
commit 6dfacbf72b53b775e8442a7fd2fca7c24b139773
tree ea798f14e90c9627e2373ea863873ad78f3694c6 tree
parent 62e1e28bf76910ffe47ddbc5c1fade41e1a65dac commit | diff
Add non-decimal integer support to type numeric.
This enhances the numeric type input function, adding support for
hexadecimal, octal, and binary integers of any size, up to the limits
of the numeric type.
Since 6fcda9aba8, such non-decimal integers have been accepted by the
parser as integer literals and passed through to numeric_in(). This
commit gives numeric_in() the ability to handle them.
While at it, simplify the handling of NaN and infinities, reducing the
number of calls to pg_strncasecmp(), and arrange for pg_strncasecmp()
to not be called at all for regular numbers. This gives a significant
performance improvement for decimal inputs, more than offsetting the
small performance hit of checking for non-decimal input.
Discussion: https://postgr.es/m/CAEZATCV8XShnmT9HZy25C%2Bo78CVOFmUN5EM9FRAZ5xvYTggPMg%40mail.gmail.com
+SELECT pg_input_error_message('0x1234.567', 'numeric');
+ pg_input_error_message
+-----------------------------------------------------
+ invalid input syntax for type numeric: "0x1234.567"
+(1 row)
+
-LINE 1: SELECT 0b100000000000000000000000000000000000000000000000000...
- ^
+ ?column?
+---------------------
+ 9223372036854775808
+(1 row)
+
-LINE 1: SELECT 0o1000000000000000000000;
- ^
+ ?column?
+---------------------
+ 9223372036854775808
+(1 row)
-LINE 1: SELECT 0x8000000000000000;
- ^
+ ?column?
+---------------------
+ 9223372036854775808
+(1 row)
+
-LINE 1: SELECT -0b10000000000000000000000000000000000000000000000000...
- ^
+ ?column?
+----------------------
+ -9223372036854775809
+(1 row)
-LINE 1: SELECT -0o1000000000000000000001;
- ^
+ ?column?
+----------------------
+ -9223372036854775809
+(1 row)
-LINE 1: SELECT -0x8000000000000001;
- ^
+ ?column?
+----------------------
+ -9223372036854775809
+(1 row)