mirror of
https://github.com/pgvector/pgvector.git
synced 2026-10-23 10:48:54 +03:00
Fixed error with avg aggregate when no matching rows - resolves #1012
Co-authored-by: Vaibhav Jain <jainva@google.com>
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## 0.8.7 (unreleased)
|
||||
|
||||
- Fixed error with `avg` aggregate when no matching rows
|
||||
|
||||
## 0.8.6 (2026-07-29)
|
||||
|
||||
- Fixed buffer overflow with IVFFlat index build on 32-bit systems - [more info](https://github.com/pgvector/pgvector/issues/1006)
|
||||
|
||||
@@ -1233,7 +1233,8 @@ vector_combine(PG_FUNCTION_ARGS)
|
||||
{
|
||||
n = n2;
|
||||
dim = STATE_DIMS(statearray2);
|
||||
CheckDim(dim);
|
||||
if (dim != 0)
|
||||
CheckDim(dim);
|
||||
statedatums = CreateStateDatums(dim);
|
||||
for (int i = 0; i < dim; i++)
|
||||
statedatums[i + 1] = Float8GetDatum(statevalues2[i + 1]);
|
||||
|
||||
@@ -713,7 +713,11 @@ ERROR: vector_combine: expected state array
|
||||
SELECT vector_combine('{0}', '{}');
|
||||
ERROR: vector_combine: expected state array
|
||||
SELECT vector_combine('{0}', '{0}');
|
||||
ERROR: vector must have at least 1 dimension
|
||||
vector_combine
|
||||
----------------
|
||||
{0}
|
||||
(1 row)
|
||||
|
||||
SELECT vector_combine('{0}', (SELECT array_agg(n) FROM generate_series(1, 16002) n));
|
||||
ERROR: vector cannot have more than 16000 dimensions
|
||||
SELECT vector_combine((SELECT array_agg(n) FROM generate_series(1, 16002) n), '{0}');
|
||||
|
||||
@@ -42,6 +42,10 @@ sub test_aggregate
|
||||
my $explain = $node->safe_psql("postgres", "EXPLAIN SELECT $agg(v) FROM tst;");
|
||||
like($explain, qr/Partial Aggregate/);
|
||||
|
||||
# Test no matching rows
|
||||
$res = $node->safe_psql("postgres", "SELECT $agg(v) FROM tst WHERE r1 < 0;");
|
||||
is($res, '');
|
||||
|
||||
# Test halfvec
|
||||
$res = $node->safe_psql("postgres", "SELECT $agg(v::halfvec) FROM tst;");
|
||||
if ($agg eq 'avg')
|
||||
@@ -55,6 +59,10 @@ sub test_aggregate
|
||||
# Does not raise overflow error in this instance due to loss of precision
|
||||
is($res, "[24576,24576,49152]");
|
||||
}
|
||||
|
||||
# Test halfvec no matching rows
|
||||
$res = $node->safe_psql("postgres", "SELECT $agg(v::halfvec) FROM tst WHERE r1 < 0;");
|
||||
is($res, '');
|
||||
}
|
||||
|
||||
test_aggregate('avg');
|
||||
|
||||
Reference in New Issue
Block a user