mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Use consistent error message for sparsevec index out of bounds [skip ci]
This commit is contained in:
@@ -94,32 +94,15 @@ CheckNnz(int nnz, int dim)
|
||||
* Ensure valid index
|
||||
*/
|
||||
static inline void
|
||||
CheckIndex(int32 *indices, int i, int dim, bool text)
|
||||
CheckIndex(int32 *indices, int i, int dim)
|
||||
{
|
||||
int32 index = indices[i];
|
||||
|
||||
if (index < 0)
|
||||
if (index < 0 || index >= dim)
|
||||
{
|
||||
if (text)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATA_EXCEPTION),
|
||||
errmsg("sparsevec index out of bounds (< 1)")));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATA_EXCEPTION),
|
||||
errmsg("sparsevec index out of bounds for binary representation (< 0)")));
|
||||
}
|
||||
|
||||
if (index >= dim)
|
||||
{
|
||||
if (text)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATA_EXCEPTION),
|
||||
errmsg("sparsevec index out of bounds (> dimensions)")));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATA_EXCEPTION),
|
||||
errmsg("sparsevec index out of bounds for binary representation (>= dimensions)")));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATA_EXCEPTION),
|
||||
errmsg("sparsevec index out of bounds")));
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
@@ -404,7 +387,7 @@ sparsevec_in(PG_FUNCTION_ARGS)
|
||||
result->indices[i] = elements[i].index;
|
||||
rvalues[i] = elements[i].value;
|
||||
|
||||
CheckIndex(result->indices, i, dim, true);
|
||||
CheckIndex(result->indices, i, dim);
|
||||
}
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
@@ -543,7 +526,7 @@ sparsevec_recv(PG_FUNCTION_ARGS)
|
||||
for (int i = 0; i < nnz; i++)
|
||||
{
|
||||
result->indices[i] = pq_getmsgint(buf, sizeof(int32));
|
||||
CheckIndex(result->indices, i, dim, false);
|
||||
CheckIndex(result->indices, i, dim);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nnz; i++)
|
||||
|
||||
@@ -208,27 +208,27 @@ ERROR: sparsevec must have at least 1 dimension
|
||||
LINE 1: SELECT '{}/-9223372036854775809'::sparsevec;
|
||||
^
|
||||
SELECT '{2147483647:1}/1'::sparsevec;
|
||||
ERROR: sparsevec index out of bounds (> dimensions)
|
||||
ERROR: sparsevec index out of bounds
|
||||
LINE 1: SELECT '{2147483647:1}/1'::sparsevec;
|
||||
^
|
||||
SELECT '{2147483648:1}/1'::sparsevec;
|
||||
ERROR: sparsevec index out of bounds (> dimensions)
|
||||
ERROR: sparsevec index out of bounds
|
||||
LINE 1: SELECT '{2147483648:1}/1'::sparsevec;
|
||||
^
|
||||
SELECT '{-2147483648:1}/1'::sparsevec;
|
||||
ERROR: sparsevec index out of bounds (< 1)
|
||||
ERROR: sparsevec index out of bounds
|
||||
LINE 1: SELECT '{-2147483648:1}/1'::sparsevec;
|
||||
^
|
||||
SELECT '{-2147483649:1}/1'::sparsevec;
|
||||
ERROR: sparsevec index out of bounds (< 1)
|
||||
ERROR: sparsevec index out of bounds
|
||||
LINE 1: SELECT '{-2147483649:1}/1'::sparsevec;
|
||||
^
|
||||
SELECT '{0:1}/1'::sparsevec;
|
||||
ERROR: sparsevec index out of bounds (< 1)
|
||||
ERROR: sparsevec index out of bounds
|
||||
LINE 1: SELECT '{0:1}/1'::sparsevec;
|
||||
^
|
||||
SELECT '{2:1}/1'::sparsevec;
|
||||
ERROR: sparsevec index out of bounds (> dimensions)
|
||||
ERROR: sparsevec index out of bounds
|
||||
LINE 1: SELECT '{2:1}/1'::sparsevec;
|
||||
^
|
||||
SELECT '{}/3'::sparsevec(3);
|
||||
|
||||
Reference in New Issue
Block a user