mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 14:01:31 +08:00
Improved avg test
This commit is contained in:
@@ -2,7 +2,7 @@ use strict;
|
||||
use warnings;
|
||||
use PostgresNode;
|
||||
use TestLib;
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
|
||||
# Initialize node
|
||||
my $node = get_new_node('node');
|
||||
@@ -13,7 +13,7 @@ $node->start;
|
||||
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
||||
$node->safe_psql("postgres", "CREATE TABLE tst (v vector(3));");
|
||||
$node->safe_psql("postgres",
|
||||
"INSERT INTO tst SELECT ARRAY[1.01 + random(), 2.01 + random(), 3.01 + random()] FROM generate_series(1, 1000000) i;"
|
||||
"INSERT INTO tst SELECT ARRAY[1.01 + random(), 2.01 + random(), 3.01 + random()] FROM generate_series(1, 1000000) i;"
|
||||
);
|
||||
|
||||
# Test avg
|
||||
@@ -25,3 +25,12 @@ like($avg, qr/,3\.5/);
|
||||
# Test explain
|
||||
my $explain = $node->safe_psql("postgres", "EXPLAIN SELECT AVG(v) FROM tst;");
|
||||
like($explain, qr/Partial Aggregate/);
|
||||
|
||||
# Test matches real
|
||||
$node->safe_psql("postgres", "CREATE TABLE tst2 (r real, v vector(1));");
|
||||
$node->safe_psql("postgres",
|
||||
"INSERT INTO tst2 SELECT t.r, ARRAY[t.r] FROM (SELECT random() AS r FROM generate_series(1, 1000000) t0) t;"
|
||||
);
|
||||
my $expected = $node->safe_psql("postgres", "SELECT AVG(r)::float4 FROM tst2;");
|
||||
$avg = $node->safe_psql("postgres", "SELECT AVG(v) FROM tst2;");
|
||||
is($avg, "[$expected]");
|
||||
|
||||
Reference in New Issue
Block a user