aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_node.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-12-14 05:40:38 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-12-14 06:17:07 +0100
commit6fcda9aba83449082124825b6d375c0a61e21c42 (patch)
treed2e23f5322bf6879e0ee328593fbc7b3f6f71702 /src/backend/parser/parse_node.c
parent60684dd834a222fefedd49b19d1f0a6189c1632e (diff)
downloadpostgresql-6fcda9aba83449082124825b6d375c0a61e21c42.tar.gz
postgresql-6fcda9aba83449082124825b6d375c0a61e21c42.zip
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. Reviewed-by: John Naylor <john.naylor@enterprisedb.com> Reviewed-by: Zhihong Yu <zyu@yugabyte.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/b239564c-cad0-b23e-c57e-166d883cb97d@enterprisedb.com
Diffstat (limited to 'src/backend/parser/parse_node.c')
-rw-r--r--src/backend/parser/parse_node.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index 4014db4b80f..d33e3c179df 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -385,11 +385,46 @@ make_const(ParseState *pstate, A_Const *aconst)
{
/* could be an oversize integer as well as a float ... */
+ int base = 10;
+ char *startptr;
+ int sign;
+ char *testvalue;
int64 val64;
char *endptr;
+ startptr = aconst->val.fval.fval;
+ if (startptr[0] == '-')
+ {
+ sign = -1;
+ startptr++;
+ }
+ else
+ sign = +1;
+ if (startptr[0] == '0')
+ {
+ if (startptr[1] == 'b' || startptr[1] == 'B')
+ {
+ base = 2;
+ startptr += 2;
+ }
+ else if (startptr[1] == 'o' || startptr[1] == 'O')
+ {
+ base = 8;
+ startptr += 2;
+ }
+ if (startptr[1] == 'x' || startptr[1] == 'X')
+ {
+ base = 16;
+ startptr += 2;
+ }
+ }
+
+ if (sign == +1)
+ testvalue = startptr;
+ else
+ testvalue = psprintf("-%s", startptr);
errno = 0;
- val64 = strtoi64(aconst->val.fval.fval, &endptr, 10);
+ val64 = strtoi64(testvalue, &endptr, base);
if (errno == 0 && *endptr == '\0')
{
/*