@ -125,6 +125,16 @@ SELECT a[1:3],
{16,25,23} | {} | {foobar,new_word} | {{elt2}}
(3 rows)
SELECT b[1:1][2][2],
d[1:1][2]
FROM arrtest;
b | d
-----------------------+---------------
{{{113,142},{1,147}}} | {}
{} | {}
{} | {{elt1,elt2}}
(3 rows)
INSERT INTO arrtest(a) VALUES('{1,null,3}');
SELECT a FROM arrtest;
a
@ -152,6 +162,107 @@ SELECT a,b,c FROM arrtest;
[4:4]={NULL} | {3,4} | {foo,new_word}
(3 rows)
-- test mixed slice/scalar subscripting
select '{{1,2,3},{4,5,6},{7,8,9}}'::int[];
int4
---------------------------
{{1,2,3},{4,5,6},{7,8,9}}
(1 row)
select ('{{1,2,3},{4,5,6},{7,8,9}}'::int[])[1:2][2];
int4
---------------
{{1,2},{4,5}}
(1 row)
select '[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}'::int[];
int4
--------------------------------------
[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
(1 row)
select ('[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}'::int[])[1:2][2];
int4
---------------
{{5,6},{8,9}}
(1 row)
-- test slices with empty lower and/or upper index
CREATE TEMP TABLE arrtest_s (
a int2[],
b int2[][]
);
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
SELECT * FROM arrtest_s;
a | b
-------------------+--------------------------------------
{1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
[0:4]={1,2,3,4,5} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
(2 rows)
SELECT a[:3], b[:2][:2] FROM arrtest_s;
a | b
-----------+---------------------------
{1,2,3} | {{1,2},{4,5}}
{1,2,3,4} | {{1,2,3},{4,5,6},{7,8,9}}
(2 rows)
SELECT a[2:], b[2:][2:] FROM arrtest_s;
a | b
-----------+---------------
{2,3,4,5} | {{5,6},{8,9}}
{3,4,5} | {{9}}
(2 rows)
SELECT a[:], b[:] FROM arrtest_s;
a | b
-------------+---------------------------
{1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
{1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
(2 rows)
-- updates
UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{11,12}, {14,15}}'
WHERE array_lower(a,1) = 1;
SELECT * FROM arrtest_s;
a | b
-------------------+--------------------------------------
[0:4]={1,2,3,4,5} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
{11,12,13,4,5} | {{11,12,3},{14,15,6},{7,8,9}}
(2 rows)
UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{25,26}, {28,29}}';
SELECT * FROM arrtest_s;
a | b
---------------------+---------------------------------------
[0:4]={1,2,3,23,24} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,25}}
{11,12,23,24,25} | {{11,12,3},{14,25,26},{7,28,29}}
(2 rows)
UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}';
SELECT * FROM arrtest_s;
a | b
------------------------+---------------------------------------
[0:4]={11,12,13,14,15} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,25}}
{11,12,13,14,15} | {{11,12,3},{14,25,26},{7,28,29}}
(2 rows)
UPDATE arrtest_s SET a[:] = '{23, 24, 25}'; -- fail, too small
ERROR: source array too small
INSERT INTO arrtest_s VALUES(NULL, NULL);
UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}'; -- fail, no good with null
ERROR: array slice subscript must provide both boundaries
DETAIL: When assigning to a slice of an empty array value, slice boundaries must be fully specified.
-- check with fixed-length-array type, such as point
SELECT f1[0:1] FROM POINT_TBL;
ERROR: slices of fixed-length arrays not implemented
SELECT f1[0:] FROM POINT_TBL;
ERROR: slices of fixed-length arrays not implemented
SELECT f1[:1] FROM POINT_TBL;
ERROR: slices of fixed-length arrays not implemented
SELECT f1[:] FROM POINT_TBL;
ERROR: slices of fixed-length arrays not implemented
--
-- test array extension
--