mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
Create real array comparison functions (that use the element datatype's
comparison functions), replacing the highly bogus bitwise array_eq. Create a btree index opclass for ANYARRAY --- it is now possible to create indexes on array columns. Arrange to cache the results of catalog lookups across multiple array operations, instead of repeating the lookups on every call. Add string_to_array and array_to_string functions. Remove singleton_array, array_accum, array_assign, and array_subscript functions, since these were for proof-of-concept and not intended to become supported functions. Minor adjustments to behavior in some corner cases with empty or zero-dimensional arrays. Joe Conway (with some editorializing by Tom Lane).
This commit is contained in:
@@ -178,19 +178,13 @@ SELECT ARRAY(select f2 from arrtest_f order by f2) AS "ARRAY";
|
||||
(1 row)
|
||||
|
||||
-- functions
|
||||
SELECT singleton_array(42) AS "{42}";
|
||||
{42}
|
||||
------
|
||||
{42}
|
||||
(1 row)
|
||||
|
||||
SELECT array_append(singleton_array(42), 6) AS "{42,6}";
|
||||
SELECT array_append(array[42], 6) AS "{42,6}";
|
||||
{42,6}
|
||||
--------
|
||||
{42,6}
|
||||
(1 row)
|
||||
|
||||
SELECT array_prepend(6, singleton_array(42)) AS "{6,42}";
|
||||
SELECT array_prepend(6, array[42]) AS "{6,42}";
|
||||
{6,42}
|
||||
--------
|
||||
{6,42}
|
||||
@@ -214,24 +208,6 @@ SELECT array_cat(ARRAY[[3,4],[5,6]], ARRAY[1,2]) AS "{{3,4},{5,6},{1,2}}";
|
||||
{{3,4},{5,6},{1,2}}
|
||||
(1 row)
|
||||
|
||||
SELECT array_subscript(n, 2) AS "1.2" FROM arrtest2;
|
||||
1.2
|
||||
-----
|
||||
1.2
|
||||
(1 row)
|
||||
|
||||
SELECT array_assign(n, 2, 9.99) AS "{1.1,9.99,1.3}" FROM arrtest2;
|
||||
{1.1,9.99,1.3}
|
||||
----------------
|
||||
{1.1,9.99,1.3}
|
||||
(1 row)
|
||||
|
||||
SELECT array_subscript(array_assign(n, 2, 9.99), 2) AS "9.99" FROM arrtest2;
|
||||
9.99
|
||||
------
|
||||
9.99
|
||||
(1 row)
|
||||
|
||||
-- operators
|
||||
SELECT a FROM arrtest WHERE b = ARRAY[[[113,142],[1,147]]];
|
||||
a
|
||||
@@ -318,3 +294,24 @@ SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}"
|
||||
{{{{{{a,bb,ccc}}}}}}
|
||||
(1 row)
|
||||
|
||||
-- test indexes on arrays
|
||||
create temp table arr_tbl (f1 int[] unique);
|
||||
NOTICE: CREATE TABLE / UNIQUE will create implicit index 'arr_tbl_f1_key' for table 'arr_tbl'
|
||||
insert into arr_tbl values ('{1,2,3}');
|
||||
insert into arr_tbl values ('{1,2}');
|
||||
-- failure expected:
|
||||
insert into arr_tbl values ('{1,2,3}');
|
||||
ERROR: Cannot insert a duplicate key into unique index arr_tbl_f1_key
|
||||
insert into arr_tbl values ('{2,3,4}');
|
||||
insert into arr_tbl values ('{1,5,3}');
|
||||
insert into arr_tbl values ('{1,2,10}');
|
||||
set enable_seqscan to off;
|
||||
select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}';
|
||||
f1
|
||||
----------
|
||||
{1,2,10}
|
||||
{1,5,3}
|
||||
(2 rows)
|
||||
|
||||
-- note: if above select doesn't produce the expected tuple order,
|
||||
-- then you didn't get an indexscan plan, and something is busted.
|
||||
|
||||
@@ -130,15 +130,11 @@ SELECT ARRAY[ARRAY['hello'],ARRAY['world']];
|
||||
SELECT ARRAY(select f2 from arrtest_f order by f2) AS "ARRAY";
|
||||
|
||||
-- functions
|
||||
SELECT singleton_array(42) AS "{42}";
|
||||
SELECT array_append(singleton_array(42), 6) AS "{42,6}";
|
||||
SELECT array_prepend(6, singleton_array(42)) AS "{6,42}";
|
||||
SELECT array_append(array[42], 6) AS "{42,6}";
|
||||
SELECT array_prepend(6, array[42]) AS "{6,42}";
|
||||
SELECT array_cat(ARRAY[1,2], ARRAY[3,4]) AS "{{1,2},{3,4}}";
|
||||
SELECT array_cat(ARRAY[1,2], ARRAY[[3,4],[5,6]]) AS "{{1,2},{3,4},{5,6}}";
|
||||
SELECT array_cat(ARRAY[[3,4],[5,6]], ARRAY[1,2]) AS "{{3,4},{5,6},{1,2}}";
|
||||
SELECT array_subscript(n, 2) AS "1.2" FROM arrtest2;
|
||||
SELECT array_assign(n, 2, 9.99) AS "{1.1,9.99,1.3}" FROM arrtest2;
|
||||
SELECT array_subscript(array_assign(n, 2, 9.99), 2) AS "9.99" FROM arrtest2;
|
||||
|
||||
-- operators
|
||||
SELECT a FROM arrtest WHERE b = ARRAY[[[113,142],[1,147]]];
|
||||
@@ -157,3 +153,17 @@ SELECT ARRAY[1,2,3]::text[]::int[]::float8[] is of (float8[]) as "TRUE";
|
||||
SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] AS "{{a,bc},{def,hijk}}";
|
||||
SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] is of (varchar[]) as "TRUE";
|
||||
SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}";
|
||||
|
||||
-- test indexes on arrays
|
||||
create temp table arr_tbl (f1 int[] unique);
|
||||
insert into arr_tbl values ('{1,2,3}');
|
||||
insert into arr_tbl values ('{1,2}');
|
||||
-- failure expected:
|
||||
insert into arr_tbl values ('{1,2,3}');
|
||||
insert into arr_tbl values ('{2,3,4}');
|
||||
insert into arr_tbl values ('{1,5,3}');
|
||||
insert into arr_tbl values ('{1,2,10}');
|
||||
set enable_seqscan to off;
|
||||
select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}';
|
||||
-- note: if above select doesn't produce the expected tuple order,
|
||||
-- then you didn't get an indexscan plan, and something is busted.
|
||||
|
||||
Reference in New Issue
Block a user