mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-10 22:56:55 +08:00
Improved error message for out of range elements
This commit is contained in:
16
src/vector.c
16
src/vector.c
@@ -200,6 +200,8 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
while (pt != NULL && *stringEnd != ']')
|
while (pt != NULL && *stringEnd != ']')
|
||||||
{
|
{
|
||||||
|
float val;
|
||||||
|
|
||||||
if (dim == VECTOR_MAX_DIM)
|
if (dim == VECTOR_MAX_DIM)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||||
@@ -215,15 +217,23 @@ vector_in(PG_FUNCTION_ARGS)
|
|||||||
errmsg("invalid input syntax for type vector: \"%s\"", lit)));
|
errmsg("invalid input syntax for type vector: \"%s\"", lit)));
|
||||||
|
|
||||||
/* Use strtof like float4in to avoid a double-rounding problem */
|
/* Use strtof like float4in to avoid a double-rounding problem */
|
||||||
x[dim] = strtof(pt, &stringEnd);
|
errno = 0;
|
||||||
CheckElement(x[dim]);
|
val = strtof(pt, &stringEnd);
|
||||||
dim++;
|
|
||||||
|
|
||||||
if (stringEnd == pt)
|
if (stringEnd == pt)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("invalid input syntax for type vector: \"%s\"", lit)));
|
errmsg("invalid input syntax for type vector: \"%s\"", lit)));
|
||||||
|
|
||||||
|
/* Check for range error like float4in */
|
||||||
|
if (errno == ERANGE && isinf(val))
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
|
||||||
|
errmsg("\"%s\" is out of range for type vector", pt)));
|
||||||
|
|
||||||
|
CheckElement(val);
|
||||||
|
x[dim++] = val;
|
||||||
|
|
||||||
while (vector_isspace(*stringEnd))
|
while (vector_isspace(*stringEnd))
|
||||||
stringEnd++;
|
stringEnd++;
|
||||||
|
|
||||||
|
|||||||
@@ -63,11 +63,11 @@ SELECT '[1.5e-38,-1.5e-38]'::vector;
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT '[4e38,1]'::vector;
|
SELECT '[4e38,1]'::vector;
|
||||||
ERROR: infinite value not allowed in vector
|
ERROR: "4e38" is out of range for type vector
|
||||||
LINE 1: SELECT '[4e38,1]'::vector;
|
LINE 1: SELECT '[4e38,1]'::vector;
|
||||||
^
|
^
|
||||||
SELECT '[-4e38,1]'::vector;
|
SELECT '[-4e38,1]'::vector;
|
||||||
ERROR: infinite value not allowed in vector
|
ERROR: "-4e38" is out of range for type vector
|
||||||
LINE 1: SELECT '[-4e38,1]'::vector;
|
LINE 1: SELECT '[-4e38,1]'::vector;
|
||||||
^
|
^
|
||||||
SELECT '[1e-46,1]'::vector;
|
SELECT '[1e-46,1]'::vector;
|
||||||
|
|||||||
Reference in New Issue
Block a user