Improved error message for out of range values for halfvec [skip ci]

This commit is contained in:
Andrew Kane
2024-04-10 13:47:45 -07:00
parent 8a29bf4619
commit a824af42fb
2 changed files with 10 additions and 10 deletions

View File

@@ -295,7 +295,15 @@ Float4ToHalf(float num)
half result = Float4ToHalfUnchecked(num);
if (unlikely(HalfIsInf(result)) && !isinf(num))
float_overflow_error();
{
char *buf = palloc(FLOAT_SHORTEST_DECIMAL_LEN);
float_to_shortest_decimal_buf(num, buf);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"%s\" is out of range for type halfvec", buf)));
}
if (unlikely(HalfIsZero(result)) && num != 0.0)
float_underflow_error();
@@ -394,14 +402,6 @@ halfvec_isspace(char ch)
}
#if PG_VERSION_NUM < 120003
static pg_noinline void
float_overflow_error(void)
{
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value out of range: overflow")));
}
static pg_noinline void
float_underflow_error(void)
{

View File

@@ -111,7 +111,7 @@ SELECT '{1,2,3}'::real[]::halfvec(3);
SELECT '{1,2,3}'::real[]::halfvec(2);
ERROR: expected 2 dimensions, not 3
SELECT '{65520,-65520}'::real[]::halfvec;
ERROR: value out of range: overflow
ERROR: "65520" is out of range for type halfvec
SELECT '{1e-8,-1e-8}'::real[]::halfvec;
ERROR: value out of range: underflow
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;