postgresql/src/test/regress/expected/arrays.out
Tom Lane e4e6459c0f 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.
2000-07-23 01:36:05 +00:00

94 lines
3.0 KiB
Plaintext

--
-- ARRAYS
--
SELECT * FROM arrtest;
a | b | c | d | e | f | g
-------------+-----------------+---------------+-------------------+---------------+-------------------+-----------------
{1,2,3,4,5} | {{{0,0},{1,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],
arrtest.b[1][1][1],
arrtest.c[1],
arrtest.d[1][1],
arrtest.e[0]
FROM arrtest;
a | b | c | d | e
----+---+--------+------+---
1 | 0 | | |
11 | | foobar | elt1 |
| | foo | |
(3 rows)
SELECT a[1], b[1][1][1], c[1], d[1][1], e[0]
FROM arrtest;
a | b | c | d | e
----+---+--------+------+---
1 | 0 | | |
11 | | foobar | elt1 |
| | foo | |
(3 rows)
SELECT a[1:3],
b[1:1][1:2][1:2],
c[1:2],
d[1:1][1:2]
FROM arrtest;
a | b | c | d
------------+-----------------+---------------+-------------------
{1,2,3} | {{{0,0},{1,2}}} | |
{11,12,23} | | {"foobar"} | {{"elt1","elt2"}}
| | {"foo","bar"} |
(3 rows)
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
SELECT *
FROM arrtest
WHERE a[1] < 5 and
c = '{"foobar"}'::_name;
a | b | c | d | e | f | g
---+---+---+---+---+---+---
(0 rows)
UPDATE arrtest
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,142},{1,147}}} | |
{16,25,23} | | {"foobar","new_word"} | {{"elt2"}}
| | {"foo","new_word"} |
(3 rows)