pgvector.git / summary / log / commit / refs
commit 42007b41ea4d856f53420bf49ba8411c3512e839
Author: Andrew Kane <andrew@ankane.org>
Date: Sun Jul 16 05:51:40 2023 +0000
Improved null check and fixed message [skip ci]
src/vector.c | 10 +++++-----
test/expected/cast.out | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/vector.c b/src/vector.c
index 86564683..3f79e3f4 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -437,6 +437,11 @@ array_to_vector(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("array must be 1-D")));
+ if (ARR_HASNULL(array) && array_contains_nulls(array))
+ ereport(ERROR,
+ (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
+ errmsg("array must not contain nulls")));
+
get_typlenbyvalalign(ARR_ELEMTYPE(array), &typlen, &typbyval, &typalign);
deconstruct_array(array, ARR_ELEMTYPE(array), typlen, typbyval, typalign, &elemsp, &nullsp, &nelemsp);
@@ -446,11 +451,6 @@ array_to_vector(PG_FUNCTION_ARGS)
result = InitVector(nelemsp);
for (int i = 0; i < nelemsp; i++)
{
- if (nullsp[i])
- ereport(ERROR,
- (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("array must not containing NULLs")));
-
/* TODO Move outside loop in 0.5.0 */
if (ARR_ELEMTYPE(array) == INT4OID)
result->x[i] = DatumGetInt32(elemsp[i]);
diff --git a/test/expected/cast.out b/test/expected/cast.out
index 37614d93..e1042de4 100644
--- a/test/expected/cast.out
+++ b/test/expected/cast.out
@@ -29,7 +29,7 @@ SELECT ARRAY[1,2,3]::numeric[]::vector;
(1 row)
SELECT '{NULL}'::real[]::vector;
-ERROR: array must not containing NULLs
+ERROR: array must not contain nulls
SELECT '{NaN}'::real[]::vector;
ERROR: NaN not allowed in vector
SELECT '{Infinity}'::real[]::vector;
[parent: 21f56374b556]