mirror of
https://github.com/postgres/postgres.git
synced 2025-12-13 14:22:43 +03:00
Require that array literals produce "rectangular" arrays, i.e. all the
subarrays of a given dimension have the same number of elements/subarrays. Also repair a longstanding undocumented (as far as I can see) ability to explicitly set array bounds in the array literal syntax. It now can deal properly with negative array indicies. Modify array_out so that arrays with non-standard lower bounds (i.e. not 1) are output with the expicit dimension syntax. This fixes a longstanding issue whereby arrays with non-default lower bounds had them changed to default after a dump/reload cycle. Modify regression tests and docs to suit, and add some minimal documentation regarding the explicit dimension syntax.
This commit is contained in:
@@ -27,11 +27,11 @@ INSERT INTO arrtest (a, b[1:2][1:2], c, d, e, f, g)
|
||||
INSERT INTO arrtest (a, b[1:2], c, d[1:2])
|
||||
VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}');
|
||||
SELECT * FROM arrtest;
|
||||
a | b | c | d | e | f | g
|
||||
-------------+-----------------+-----------+---------------+-----------+-----------------+-------------
|
||||
{1,2,3,4,5} | {{{0,0},{1,2}}} | {} | {} | {1.1,2.2} | {} | {}
|
||||
{11,12,23} | {{3,4},{4,5}} | {foobar} | {{elt1,elt2}} | {3.4,6.7} | {"abc ",abcde} | {abc,abcde}
|
||||
{} | {3,4} | {foo,bar} | {bar,foo} | | |
|
||||
a | b | c | d | e | f | g
|
||||
-------------+-----------------+-----------+---------------+-----------------+-----------------+-------------
|
||||
{1,2,3,4,5} | {{{0,0},{1,2}}} | {} | {} | [0:1]={1.1,2.2} | {} | {}
|
||||
{11,12,23} | {{3,4},{4,5}} | {foobar} | {{elt1,elt2}} | {3.4,6.7} | {"abc ",abcde} | {abc,abcde}
|
||||
{} | {3,4} | {foo,bar} | {bar,foo} | | |
|
||||
(3 rows)
|
||||
|
||||
SELECT arrtest.a[1],
|
||||
@@ -184,9 +184,9 @@ SELECT array_append(array[42], 6) AS "{42,6}";
|
||||
(1 row)
|
||||
|
||||
SELECT array_prepend(6, array[42]) AS "{6,42}";
|
||||
{6,42}
|
||||
--------
|
||||
{6,42}
|
||||
{6,42}
|
||||
--------------
|
||||
[0:1]={6,42}
|
||||
(1 row)
|
||||
|
||||
SELECT array_cat(ARRAY[1,2], ARRAY[3,4]) AS "{1,2,3,4}";
|
||||
@@ -196,9 +196,9 @@ SELECT array_cat(ARRAY[1,2], ARRAY[3,4]) AS "{1,2,3,4}";
|
||||
(1 row)
|
||||
|
||||
SELECT array_cat(ARRAY[1,2], ARRAY[[3,4],[5,6]]) AS "{{1,2},{3,4},{5,6}}";
|
||||
{{1,2},{3,4},{5,6}}
|
||||
---------------------
|
||||
{{1,2},{3,4},{5,6}}
|
||||
{{1,2},{3,4},{5,6}}
|
||||
--------------------------------
|
||||
[0:2][1:2]={{1,2},{3,4},{5,6}}
|
||||
(1 row)
|
||||
|
||||
SELECT array_cat(ARRAY[[3,4],[5,6]], ARRAY[1,2]) AS "{{3,4},{5,6},{1,2}}";
|
||||
@@ -227,9 +227,9 @@ SELECT ARRAY[1,2] || 3 AS "{1,2,3}";
|
||||
(1 row)
|
||||
|
||||
SELECT 0 || ARRAY[1,2] AS "{0,1,2}";
|
||||
{0,1,2}
|
||||
---------
|
||||
{0,1,2}
|
||||
{0,1,2}
|
||||
---------------
|
||||
[0:2]={0,1,2}
|
||||
(1 row)
|
||||
|
||||
SELECT ARRAY[1,2] || ARRAY[3,4] AS "{1,2,3,4}";
|
||||
@@ -257,9 +257,9 @@ SELECT ARRAY[0,0] || ARRAY[1,1] || ARRAY[2,2] AS "{0,0,1,1,2,2}";
|
||||
(1 row)
|
||||
|
||||
SELECT 0 || ARRAY[1,2] || 3 AS "{0,1,2,3}";
|
||||
{0,1,2,3}
|
||||
-----------
|
||||
{0,1,2,3}
|
||||
{0,1,2,3}
|
||||
-----------------
|
||||
[0:3]={0,1,2,3}
|
||||
(1 row)
|
||||
|
||||
-- array casts
|
||||
|
||||
@@ -72,29 +72,29 @@ create table domarrtest
|
||||
( testint4arr domainint4arr
|
||||
, testtextarr domaintextarr
|
||||
);
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}}');
|
||||
INSERT INTO domarrtest values ('{{2,2}{2,2}}', '{{"a","b"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}{"e"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a"}{"c"}}');
|
||||
INSERT INTO domarrtest values (NULL, '{{"a","b"}{"c","d","e"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
|
||||
INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
|
||||
INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
|
||||
select * from domarrtest;
|
||||
testint4arr | testtextarr
|
||||
---------------+---------------------
|
||||
{2,2} | {{a,c},{"",d}}
|
||||
{{2,2},{0,2}} | {{a,b}}
|
||||
{2,2} | {{a},{c},{e}}
|
||||
{2,2} | {{c},{""}}
|
||||
| {{a,c,""},{"",d,e}}
|
||||
{2,2} | {{a,b},{c,d}}
|
||||
{{2,2},{2,2}} | {{a,b}}
|
||||
{2,2} | {{a,b},{c,d},{e,f}}
|
||||
{2,2} | {{a},{c}}
|
||||
| {{a,b,c},{d,e,f}}
|
||||
(5 rows)
|
||||
|
||||
select testint4arr[1], testtextarr[2:2] from domarrtest;
|
||||
testint4arr | testtextarr
|
||||
-------------+-------------
|
||||
2 | {{"",d}}
|
||||
2 | {{c,d}}
|
||||
|
|
||||
2 | {{c,d}}
|
||||
2 | {{c}}
|
||||
2 | {{""}}
|
||||
| {{"",d,e}}
|
||||
| {{d,e,f}}
|
||||
(5 rows)
|
||||
|
||||
drop table domarrtest;
|
||||
|
||||
@@ -66,11 +66,11 @@ create table domarrtest
|
||||
( testint4arr domainint4arr
|
||||
, testtextarr domaintextarr
|
||||
);
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}}');
|
||||
INSERT INTO domarrtest values ('{{2,2}{2,2}}', '{{"a","b"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"}{"c","d"}{"e"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a"}{"c"}}');
|
||||
INSERT INTO domarrtest values (NULL, '{{"a","b"}{"c","d","e"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
|
||||
INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
|
||||
INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
|
||||
INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
|
||||
select * from domarrtest;
|
||||
select testint4arr[1], testtextarr[2:2] from domarrtest;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user