mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Use integer[] for consistency [skip ci]
This commit is contained in:
@@ -81,14 +81,14 @@ CREATE FUNCTION intvec(intvec, integer, boolean) RETURNS intvec
|
|||||||
CREATE FUNCTION array_to_intvec(integer[], integer, boolean) RETURNS intvec
|
CREATE FUNCTION array_to_intvec(integer[], integer, boolean) RETURNS intvec
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE FUNCTION intvec_to_int(intvec, integer, boolean) RETURNS int[]
|
CREATE FUNCTION intvec_to_integer(intvec, integer, boolean) RETURNS integer[]
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE CAST (intvec AS intvec)
|
CREATE CAST (intvec AS intvec)
|
||||||
WITH FUNCTION intvec(intvec, integer, boolean) AS IMPLICIT;
|
WITH FUNCTION intvec(intvec, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
CREATE CAST (intvec AS int[])
|
CREATE CAST (intvec AS integer[])
|
||||||
WITH FUNCTION intvec_to_int(intvec, integer, boolean) AS ASSIGNMENT;
|
WITH FUNCTION intvec_to_integer(intvec, integer, boolean) AS ASSIGNMENT;
|
||||||
|
|
||||||
CREATE CAST (integer[] AS intvec)
|
CREATE CAST (integer[] AS intvec)
|
||||||
WITH FUNCTION array_to_intvec(integer[], integer, boolean) AS ASSIGNMENT;
|
WITH FUNCTION array_to_intvec(integer[], integer, boolean) AS ASSIGNMENT;
|
||||||
|
|||||||
@@ -735,7 +735,7 @@ CREATE FUNCTION intvec(intvec, integer, boolean) RETURNS intvec
|
|||||||
CREATE FUNCTION array_to_intvec(integer[], integer, boolean) RETURNS intvec
|
CREATE FUNCTION array_to_intvec(integer[], integer, boolean) RETURNS intvec
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE FUNCTION intvec_to_int(intvec, integer, boolean) RETURNS int[]
|
CREATE FUNCTION intvec_to_integer(intvec, integer, boolean) RETURNS integer[]
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
-- intvec casts
|
-- intvec casts
|
||||||
@@ -743,8 +743,8 @@ CREATE FUNCTION intvec_to_int(intvec, integer, boolean) RETURNS int[]
|
|||||||
CREATE CAST (intvec AS intvec)
|
CREATE CAST (intvec AS intvec)
|
||||||
WITH FUNCTION intvec(intvec, integer, boolean) AS IMPLICIT;
|
WITH FUNCTION intvec(intvec, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
CREATE CAST (intvec AS int[])
|
CREATE CAST (intvec AS integer[])
|
||||||
WITH FUNCTION intvec_to_int(intvec, integer, boolean) AS ASSIGNMENT;
|
WITH FUNCTION intvec_to_integer(intvec, integer, boolean) AS ASSIGNMENT;
|
||||||
|
|
||||||
CREATE CAST (integer[] AS intvec)
|
CREATE CAST (integer[] AS intvec)
|
||||||
WITH FUNCTION array_to_intvec(integer[], integer, boolean) AS ASSIGNMENT;
|
WITH FUNCTION array_to_intvec(integer[], integer, boolean) AS ASSIGNMENT;
|
||||||
|
|||||||
@@ -416,11 +416,11 @@ array_to_intvec(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert int vector to int[]
|
* Convert int vector to integer[]
|
||||||
*/
|
*/
|
||||||
FUNCTION_PREFIX PG_FUNCTION_INFO_V1(intvec_to_int);
|
FUNCTION_PREFIX PG_FUNCTION_INFO_V1(intvec_to_integer);
|
||||||
Datum
|
Datum
|
||||||
intvec_to_int(PG_FUNCTION_ARGS)
|
intvec_to_integer(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
IntVector *vec = PG_GETARG_INTVEC_P(0);
|
IntVector *vec = PG_GETARG_INTVEC_P(0);
|
||||||
Datum *datums;
|
Datum *datums;
|
||||||
|
|||||||
@@ -140,33 +140,33 @@ SELECT '{1e-8,-1e-8}'::real[]::halfvec;
|
|||||||
[0,-0]
|
[0,-0]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT '[1,2,3]'::intvec::int[];
|
SELECT '[1,2,3]'::intvec::integer[];
|
||||||
int4
|
int4
|
||||||
---------
|
---------
|
||||||
{1,2,3}
|
{1,2,3}
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT '{1,2,3}'::int[]::intvec;
|
SELECT '{1,2,3}'::integer[]::intvec;
|
||||||
intvec
|
intvec
|
||||||
---------
|
---------
|
||||||
[1,2,3]
|
[1,2,3]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT '{1,2,3}'::int[]::intvec(3);
|
SELECT '{1,2,3}'::integer[]::intvec(3);
|
||||||
intvec
|
intvec
|
||||||
---------
|
---------
|
||||||
[1,2,3]
|
[1,2,3]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT '{1,2,3}'::int[]::intvec(2);
|
SELECT '{1,2,3}'::integer[]::intvec(2);
|
||||||
ERROR: expected 2 dimensions, not 3
|
ERROR: expected 2 dimensions, not 3
|
||||||
SELECT '{127,-128}'::int[]::intvec;
|
SELECT '{127,-128}'::integer[]::intvec;
|
||||||
intvec
|
intvec
|
||||||
------------
|
------------
|
||||||
[127,-128]
|
[127,-128]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT '{128,-129}'::int[]::intvec;
|
SELECT '{128,-129}'::integer[]::intvec;
|
||||||
ERROR: value "128" is out of range for type intvec
|
ERROR: value "128" is out of range for type intvec
|
||||||
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;
|
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;
|
||||||
sparsevec
|
sparsevec
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ SELECT '{1,2,3}'::real[]::halfvec(2);
|
|||||||
SELECT '{65520,-65520}'::real[]::halfvec;
|
SELECT '{65520,-65520}'::real[]::halfvec;
|
||||||
SELECT '{1e-8,-1e-8}'::real[]::halfvec;
|
SELECT '{1e-8,-1e-8}'::real[]::halfvec;
|
||||||
|
|
||||||
SELECT '[1,2,3]'::intvec::int[];
|
SELECT '[1,2,3]'::intvec::integer[];
|
||||||
|
|
||||||
SELECT '{1,2,3}'::int[]::intvec;
|
SELECT '{1,2,3}'::integer[]::intvec;
|
||||||
SELECT '{1,2,3}'::int[]::intvec(3);
|
SELECT '{1,2,3}'::integer[]::intvec(3);
|
||||||
SELECT '{1,2,3}'::int[]::intvec(2);
|
SELECT '{1,2,3}'::integer[]::intvec(2);
|
||||||
SELECT '{127,-128}'::int[]::intvec;
|
SELECT '{127,-128}'::integer[]::intvec;
|
||||||
SELECT '{128,-129}'::int[]::intvec;
|
SELECT '{128,-129}'::integer[]::intvec;
|
||||||
|
|
||||||
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;
|
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec;
|
||||||
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec(5);
|
SELECT '[0,1.5,0,3.5,0]'::vector::sparsevec(5);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ for (1 .. 50)
|
|||||||
is($expected, $actual);
|
is($expected, $actual);
|
||||||
|
|
||||||
# Test intvec
|
# Test intvec
|
||||||
$actual = $node->safe_psql("postgres", "SELECT intvec_cmp(v::int[]::intvec, '$query'::int[]::intvec) FROM tst");
|
$actual = $node->safe_psql("postgres", "SELECT intvec_cmp(v::integer[]::intvec, '$query'::integer[]::intvec) FROM tst");
|
||||||
is($expected, $actual);
|
is($expected, $actual);
|
||||||
|
|
||||||
# Test sparsevec
|
# Test sparsevec
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ for my $function (@functions)
|
|||||||
is($expected, $actual, "halfvec $function");
|
is($expected, $actual, "halfvec $function");
|
||||||
|
|
||||||
# Test intvec
|
# Test intvec
|
||||||
$actual = $node->safe_psql("postgres", "SELECT $function(v::real[]::int[]::intvec, '$query'::vector::real[]::int[]::intvec) FROM tst");
|
$actual = $node->safe_psql("postgres", "SELECT $function(v::real[]::integer[]::intvec, '$query'::vector::real[]::integer[]::intvec) FROM tst");
|
||||||
is($expected, $actual, "intvec $function");
|
is($expected, $actual, "intvec $function");
|
||||||
|
|
||||||
# Test sparsevec
|
# Test sparsevec
|
||||||
|
|||||||
Reference in New Issue
Block a user