1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-10 14:22:35 +03:00

Further cleanup of array behavior. Slice assignments to arrays with

varlena elements work now.  Allow assignment to previously-nonexistent
subscript position to extend array, but only for 1-D arrays and only
if adjacent to existing positions (could do more if we had a way to
represent nulls in arrays, but I don't want to tackle that now).
Arrange for assignment of NULL to an array element in UPDATE to be a
no-op, rather than setting the entire array to NULL as it used to.
(Throwing an error would be a reasonable alternative, but it's never
done that...)  Update regress test accordingly.
This commit is contained in:
Tom Lane
2000-07-23 01:36:05 +00:00
parent ef2a6b8b83
commit e4e6459c0f
4 changed files with 618 additions and 255 deletions

View File

@@ -39,17 +39,17 @@ SELECT a[1:3],
a | b | c | d
------------+-----------------+---------------+-------------------
{1,2,3} | {{{0,0},{1,2}}} | |
{11,12,23} | | | {{"elt1","elt2"}}
{11,12,23} | | {"foobar"} | {{"elt1","elt2"}}
| | {"foo","bar"} |
(3 rows)
-- returns three different results--
SELECT array_dims(arrtest.b) AS x;
x
-----------------
[1:1][1:2][1:2]
[1:2][1:2]
[1:2]
SELECT array_dims(a) AS a,array_dims(b) AS b,array_dims(c) AS c
FROM arrtest;
a | b | c
-------+-----------------+-------
[1:5] | [1:1][1:2][1:2] |
[1:3] | [1:2][1:2] | [1:1]
| [1:2] | [1:2]
(3 rows)
-- returns nothing
@@ -62,18 +62,32 @@ SELECT *
(0 rows)
UPDATE arrtest
SET a[1:2] = '{16,25}',
b[1:1][1:1][1:2] = '{113, 117}',
c[1:1] = '{"new_word"}';
SET a[1:2] = '{16,25}'
WHERE NOT a = '{}'::_int2;
UPDATE arrtest
SET b[1:1][1:1][1:2] = '{113, 117}',
b[1:1][1:2][2:2] = '{142, 147}'
WHERE array_dims(b) = '[1:1][1:2][1:2]';
UPDATE arrtest
SET c[2:2] = '{"new_word"}'
WHERE array_dims(c) is not null;
SELECT a,b,c FROM arrtest;
a | b | c
---------------+-----------------------+-----------------------
{16,25,3,4,5} | {{{113,142},{1,147}}} | {}
{16,25,23} | {{3,4},{4,5}} | {"foobar","new_word"}
{} | {3,4} | {"foo","new_word"}
(3 rows)
SELECT a[1:3],
b[1:1][1:2][1:2],
c[1:2],
d[1:1][2:2]
FROM arrtest;
a | b | c | d
------------+---------------------+--------------------+------------
{16,25,3} | {{{113,117},{1,2}}} | |
{16,25,23} | | | {{"elt2"}}
| | {"new_word","bar"} |
a | b | c | d
------------+-----------------------+-----------------------+------------
{16,25,3} | {{{113,142},{1,147}}} | |
{16,25,23} | | {"foobar","new_word"} | {{"elt2"}}
| | {"foo","new_word"} |
(3 rows)

View File

@@ -20,8 +20,8 @@ SELECT a[1:3],
d[1:1][1:2]
FROM arrtest;
-- returns three different results--
SELECT array_dims(arrtest.b) AS x;
SELECT array_dims(a) AS a,array_dims(b) AS b,array_dims(c) AS c
FROM arrtest;
-- returns nothing
SELECT *
@@ -30,9 +30,19 @@ SELECT *
c = '{"foobar"}'::_name;
UPDATE arrtest
SET a[1:2] = '{16,25}',
b[1:1][1:1][1:2] = '{113, 117}',
c[1:1] = '{"new_word"}';
SET a[1:2] = '{16,25}'
WHERE NOT a = '{}'::_int2;
UPDATE arrtest
SET b[1:1][1:1][1:2] = '{113, 117}',
b[1:1][1:2][2:2] = '{142, 147}'
WHERE array_dims(b) = '[1:1][1:2][1:2]';
UPDATE arrtest
SET c[2:2] = '{"new_word"}'
WHERE array_dims(c) is not null;
SELECT a,b,c FROM arrtest;
SELECT a[1:3],
b[1:1][1:2][1:2],