diff options
Diffstat (limited to 'src/backend/parser/parse_node.c')
-rw-r--r-- | src/backend/parser/parse_node.c | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c index a49c985d36e..4d39cf95945 100644 --- a/src/backend/parser/parse_node.c +++ b/src/backend/parser/parse_node.c @@ -382,55 +382,56 @@ make_const(ParseState *pstate, A_Const *aconst) break; case T_Float: - { - /* could be an oversize integer as well as a float ... */ - - int64 val64; - char *endptr; - - errno = 0; - val64 = strtoi64(aconst->val.fval.fval, &endptr, 10); - if (errno == 0 && *endptr == '\0') { - /* - * It might actually fit in int32. Probably only INT_MIN can - * occur, but we'll code the test generally just to be sure. - */ - int32 val32 = (int32) val64; + /* could be an oversize integer as well as a float ... */ - if (val64 == (int64) val32) - { - val = Int32GetDatum(val32); + int64 val64; + char *endptr; - typeid = INT4OID; - typelen = sizeof(int32); - typebyval = true; + errno = 0; + val64 = strtoi64(aconst->val.fval.fval, &endptr, 10); + if (errno == 0 && *endptr == '\0') + { + /* + * It might actually fit in int32. Probably only INT_MIN + * can occur, but we'll code the test generally just to be + * sure. + */ + int32 val32 = (int32) val64; + + if (val64 == (int64) val32) + { + val = Int32GetDatum(val32); + + typeid = INT4OID; + typelen = sizeof(int32); + typebyval = true; + } + else + { + val = Int64GetDatum(val64); + + typeid = INT8OID; + typelen = sizeof(int64); + typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */ + } } else { - val = Int64GetDatum(val64); - - typeid = INT8OID; - typelen = sizeof(int64); - typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */ + /* arrange to report location if numeric_in() fails */ + setup_parser_errposition_callback(&pcbstate, pstate, aconst->location); + val = DirectFunctionCall3(numeric_in, + CStringGetDatum(aconst->val.fval.fval), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); + cancel_parser_errposition_callback(&pcbstate); + + typeid = NUMERICOID; + typelen = -1; /* variable len */ + typebyval = false; } + break; } - else - { - /* arrange to report location if numeric_in() fails */ - setup_parser_errposition_callback(&pcbstate, pstate, aconst->location); - val = DirectFunctionCall3(numeric_in, - CStringGetDatum(aconst->val.fval.fval), - ObjectIdGetDatum(InvalidOid), - Int32GetDatum(-1)); - cancel_parser_errposition_callback(&pcbstate); - - typeid = NUMERICOID; - typelen = -1; /* variable len */ - typebyval = false; - } - break; - } case T_Boolean: val = BoolGetDatum(boolVal(&aconst->val)); |