mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-12 07:36:55 +08:00
Improved error message for out of range values for halfvec [skip ci]
This commit is contained in:
@@ -295,7 +295,15 @@ Float4ToHalf(float num)
|
|||||||
half result = Float4ToHalfUnchecked(num);
|
half result = Float4ToHalfUnchecked(num);
|
||||||
|
|
||||||
if (unlikely(HalfIsInf(result)) && !isinf(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)
|
if (unlikely(HalfIsZero(result)) && num != 0.0)
|
||||||
float_underflow_error();
|
float_underflow_error();
|
||||||
|
|
||||||
@@ -394,14 +402,6 @@ halfvec_isspace(char ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 120003
|
#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
|
static pg_noinline void
|
||||||
float_underflow_error(void)
|
float_underflow_error(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ SELECT '{1,2,3}'::real[]::halfvec(3);
|
|||||||
SELECT '{1,2,3}'::real[]::halfvec(2);
|
SELECT '{1,2,3}'::real[]::halfvec(2);
|
||||||
ERROR: expected 2 dimensions, not 3
|
ERROR: expected 2 dimensions, not 3
|
||||||
SELECT '{65520,-65520}'::real[]::halfvec;
|
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;
|
SELECT '{1e-8,-1e-8}'::real[]::halfvec;
|
||||||
ERROR: value out of range: underflow
|
ERROR: value out of range: underflow
|
||||||
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;
|
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;
|
||||||
|
|||||||
Reference in New Issue
Block a user