subvector函数的参数2代表的起始位置增加范围限制

This commit is contained in:
linqiang
2024-12-03 16:01:05 +08:00
committed by Lin_qiang
parent 4bd5ee6339
commit 46830c7eee

View File

@ -1099,6 +1099,14 @@ Datum subvector(PG_FUNCTION_ARGS)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("vector must have at least 1 dimension")));
}
/* Indexing starts at 1, like substring */
if (start < 1) {
ereport(WARNING, (errmsg("when the start position is less than 1, it will begin with the first dimension")));
start = 1;
} else if (start > a->dim) {
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("vector must have at least 1 dimension")));
}
/*
* Check if (start + count > a->dim), avoiding integer overflow. a->dim
* and count are both positive, so a->dim - count won't overflow.
@ -1109,13 +1117,6 @@ Datum subvector(PG_FUNCTION_ARGS)
end = start + count;
}
/* Indexing starts at 1, like substring */
if (start < 1) {
start = 1;
} else if (start > a->dim) {
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("vector must have at least 1 dimension")));
}
dim = end - start;
CheckDim(dim);
result = InitVector(dim);