2000-01-15 20:11:40 +01:00
|
|
|
--
|
|
|
|
-- ARRAYS
|
|
|
|
--
|
2001-05-21 18:54:46 +02:00
|
|
|
CREATE TABLE arrtest (
|
|
|
|
a int2[],
|
|
|
|
b int4[][][],
|
|
|
|
c name[],
|
|
|
|
d text[][],
|
|
|
|
e float8[],
|
|
|
|
f char(5)[],
|
|
|
|
g varchar(5)[]
|
|
|
|
);
|
|
|
|
--
|
2004-06-09 21:08:20 +02:00
|
|
|
-- only the 'e' array is 0-based, the others are 1-based.
|
2001-05-21 18:54:46 +02:00
|
|
|
--
|
2004-06-09 21:08:20 +02:00
|
|
|
INSERT INTO arrtest (a[1:5], b[1:1][1:2][1:2], c, d, f, g)
|
2002-08-27 22:29:11 +02:00
|
|
|
VALUES ('{1,2,3,4,5}', '{{{0,0},{1,2}}}', '{}', '{}', '{}', '{}');
|
2001-05-21 18:54:46 +02:00
|
|
|
UPDATE arrtest SET e[0] = '1.1';
|
|
|
|
UPDATE arrtest SET e[1] = '2.2';
|
|
|
|
INSERT INTO arrtest (f)
|
|
|
|
VALUES ('{"too long"}');
|
|
|
|
ERROR: value too long for type character(5)
|
2004-06-09 21:08:20 +02:00
|
|
|
INSERT INTO arrtest (a, b[1:2][1:2], c, d, e, f, g)
|
2001-05-21 18:54:46 +02:00
|
|
|
VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}',
|
|
|
|
'{{"elt1", "elt2"}}', '{"3.4", "6.7"}',
|
|
|
|
'{"abc","abcde"}', '{"abc","abcde"}');
|
2004-06-09 21:08:20 +02:00
|
|
|
INSERT INTO arrtest (a, b[1:2], c, d[1:2])
|
2001-05-21 18:54:46 +02:00
|
|
|
VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}');
|
2000-01-15 20:11:40 +01:00
|
|
|
SELECT * FROM arrtest;
|
2004-08-05 05:30:44 +02:00
|
|
|
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} | | |
|
1997-04-29 16:23:51 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-15 20:11:40 +01:00
|
|
|
SELECT arrtest.a[1],
|
1997-04-29 16:23:51 +02:00
|
|
|
arrtest.b[1][1][1],
|
|
|
|
arrtest.c[1],
|
2000-01-15 20:11:40 +01:00
|
|
|
arrtest.d[1][1],
|
1997-04-29 16:23:51 +02:00
|
|
|
arrtest.e[0]
|
|
|
|
FROM arrtest;
|
2004-06-09 21:08:20 +02:00
|
|
|
a | b | c | d | e
|
|
|
|
----+---+--------+------+-----
|
|
|
|
1 | 0 | | | 1.1
|
|
|
|
11 | | foobar | elt1 |
|
|
|
|
| | foo | |
|
1997-04-29 16:23:51 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-15 20:11:40 +01:00
|
|
|
SELECT a[1], b[1][1][1], c[1], d[1][1], e[0]
|
1997-04-29 16:23:51 +02:00
|
|
|
FROM arrtest;
|
2004-06-09 21:08:20 +02:00
|
|
|
a | b | c | d | e
|
|
|
|
----+---+--------+------+-----
|
|
|
|
1 | 0 | | | 1.1
|
|
|
|
11 | | foobar | elt1 |
|
|
|
|
| | foo | |
|
1997-04-29 16:23:51 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-15 20:11:40 +01:00
|
|
|
SELECT a[1:3],
|
|
|
|
b[1:1][1:2][1:2],
|
|
|
|
c[1:2],
|
|
|
|
d[1:1][1:2]
|
|
|
|
FROM arrtest;
|
2001-11-29 22:02:41 +01:00
|
|
|
a | b | c | d
|
|
|
|
------------+-----------------+-----------+---------------
|
|
|
|
{1,2,3} | {{{0,0},{1,2}}} | |
|
|
|
|
{11,12,23} | | {foobar} | {{elt1,elt2}}
|
|
|
|
| | {foo,bar} |
|
2000-01-15 20:11:40 +01:00
|
|
|
(3 rows)
|
|
|
|
|
2000-07-23 03:36:05 +02:00
|
|
|
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]
|
1997-04-29 16:23:51 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-15 20:11:40 +01:00
|
|
|
-- returns nothing
|
|
|
|
SELECT *
|
1997-04-29 16:23:51 +02:00
|
|
|
FROM arrtest
|
2000-01-15 20:11:40 +01:00
|
|
|
WHERE a[1] < 5 and
|
|
|
|
c = '{"foobar"}'::_name;
|
|
|
|
a | b | c | d | e | f | g
|
|
|
|
---+---+---+---+---+---+---
|
1997-04-29 16:23:51 +02:00
|
|
|
(0 rows)
|
|
|
|
|
2000-01-15 20:11:40 +01:00
|
|
|
UPDATE arrtest
|
2000-07-23 03:36:05 +02:00
|
|
|
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;
|
2001-11-29 22:02:41 +01:00
|
|
|
a | b | c
|
|
|
|
---------------+-----------------------+-------------------
|
2000-07-23 03:36:05 +02:00
|
|
|
{16,25,3,4,5} | {{{113,142},{1,147}}} | {}
|
2001-11-29 22:02:41 +01:00
|
|
|
{} | {3,4} | {foo,new_word}
|
|
|
|
{16,25,23} | {{3,4},{4,5}} | {foobar,new_word}
|
2000-07-23 03:36:05 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-15 20:11:40 +01:00
|
|
|
SELECT a[1:3],
|
|
|
|
b[1:1][1:2][1:2],
|
|
|
|
c[1:2],
|
|
|
|
d[1:1][2:2]
|
1997-04-29 16:23:51 +02:00
|
|
|
FROM arrtest;
|
2001-11-29 22:02:41 +01:00
|
|
|
a | b | c | d
|
|
|
|
------------+-----------------------+-------------------+----------
|
|
|
|
{16,25,3} | {{{113,142},{1,147}}} | |
|
|
|
|
| | {foo,new_word} |
|
|
|
|
{16,25,23} | | {foobar,new_word} | {{elt2}}
|
1997-04-29 16:23:51 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2003-04-09 01:20:04 +02:00
|
|
|
--
|
|
|
|
-- array expressions and operators
|
|
|
|
--
|
|
|
|
-- table creation and INSERTs
|
|
|
|
CREATE TEMP TABLE arrtest2 (i integer ARRAY[4], f float8[], n numeric[], t text[], d timestamp[]);
|
|
|
|
INSERT INTO arrtest2 VALUES(
|
|
|
|
ARRAY[[[113,142],[1,147]]],
|
|
|
|
ARRAY[1.1,1.2,1.3]::float8[],
|
|
|
|
ARRAY[1.1,1.2,1.3],
|
|
|
|
ARRAY[[['aaa','aab'],['aba','abb'],['aca','acb']],[['baa','bab'],['bba','bbb'],['bca','bcb']]],
|
|
|
|
ARRAY['19620326','19931223','19970117']::timestamp[]
|
|
|
|
);
|
|
|
|
-- some more test data
|
|
|
|
CREATE TEMP TABLE arrtest_f (f0 int, f1 text, f2 float8);
|
|
|
|
insert into arrtest_f values(1,'cat1',1.21);
|
|
|
|
insert into arrtest_f values(2,'cat1',1.24);
|
|
|
|
insert into arrtest_f values(3,'cat1',1.18);
|
|
|
|
insert into arrtest_f values(4,'cat1',1.26);
|
|
|
|
insert into arrtest_f values(5,'cat1',1.15);
|
|
|
|
insert into arrtest_f values(6,'cat2',1.15);
|
|
|
|
insert into arrtest_f values(7,'cat2',1.26);
|
|
|
|
insert into arrtest_f values(8,'cat2',1.32);
|
|
|
|
insert into arrtest_f values(9,'cat2',1.30);
|
|
|
|
CREATE TEMP TABLE arrtest_i (f0 int, f1 text, f2 int);
|
|
|
|
insert into arrtest_i values(1,'cat1',21);
|
|
|
|
insert into arrtest_i values(2,'cat1',24);
|
|
|
|
insert into arrtest_i values(3,'cat1',18);
|
|
|
|
insert into arrtest_i values(4,'cat1',26);
|
|
|
|
insert into arrtest_i values(5,'cat1',15);
|
|
|
|
insert into arrtest_i values(6,'cat2',15);
|
|
|
|
insert into arrtest_i values(7,'cat2',26);
|
|
|
|
insert into arrtest_i values(8,'cat2',32);
|
|
|
|
insert into arrtest_i values(9,'cat2',30);
|
|
|
|
-- expressions
|
|
|
|
SELECT t.f[1][3][1] AS "131", t.f[2][2][1] AS "221" FROM (
|
|
|
|
SELECT ARRAY[[[111,112],[121,122],[131,132]],[[211,212],[221,122],[231,232]]] AS f
|
|
|
|
) AS t;
|
|
|
|
131 | 221
|
|
|
|
-----+-----
|
|
|
|
131 | 221
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[[[[[['hello'],['world']]]]]];
|
|
|
|
array
|
|
|
|
---------------------------
|
|
|
|
{{{{{{hello},{world}}}}}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[ARRAY['hello'],ARRAY['world']];
|
|
|
|
array
|
|
|
|
-------------------
|
|
|
|
{{hello},{world}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY(select f2 from arrtest_f order by f2) AS "ARRAY";
|
|
|
|
ARRAY
|
|
|
|
-----------------------------------------------
|
|
|
|
{1.15,1.15,1.18,1.21,1.24,1.26,1.26,1.3,1.32}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- functions
|
2003-06-27 02:33:26 +02:00
|
|
|
SELECT array_append(array[42], 6) AS "{42,6}";
|
2003-04-09 01:20:04 +02:00
|
|
|
{42,6}
|
|
|
|
--------
|
|
|
|
{42,6}
|
|
|
|
(1 row)
|
|
|
|
|
2003-06-27 02:33:26 +02:00
|
|
|
SELECT array_prepend(6, array[42]) AS "{6,42}";
|
2004-08-05 05:30:44 +02:00
|
|
|
{6,42}
|
|
|
|
--------------
|
|
|
|
[0:1]={6,42}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
2003-08-18 01:43:27 +02:00
|
|
|
SELECT array_cat(ARRAY[1,2], ARRAY[3,4]) AS "{1,2,3,4}";
|
|
|
|
{1,2,3,4}
|
|
|
|
-----------
|
|
|
|
{1,2,3,4}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT array_cat(ARRAY[1,2], ARRAY[[3,4],[5,6]]) AS "{{1,2},{3,4},{5,6}}";
|
2004-08-05 05:30:44 +02:00
|
|
|
{{1,2},{3,4},{5,6}}
|
|
|
|
--------------------------------
|
|
|
|
[0:2][1:2]={{1,2},{3,4},{5,6}}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT array_cat(ARRAY[[3,4],[5,6]], ARRAY[1,2]) AS "{{3,4},{5,6},{1,2}}";
|
|
|
|
{{3,4},{5,6},{1,2}}
|
|
|
|
---------------------
|
|
|
|
{{3,4},{5,6},{1,2}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- operators
|
|
|
|
SELECT a FROM arrtest WHERE b = ARRAY[[[113,142],[1,147]]];
|
|
|
|
a
|
|
|
|
---------------
|
|
|
|
{16,25,3,4,5}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT NOT ARRAY[1.1,1.2,1.3] = ARRAY[1.1,1.2,1.3] AS "FALSE";
|
|
|
|
FALSE
|
|
|
|
-------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[1,2] || 3 AS "{1,2,3}";
|
|
|
|
{1,2,3}
|
|
|
|
---------
|
|
|
|
{1,2,3}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT 0 || ARRAY[1,2] AS "{0,1,2}";
|
2004-08-05 05:30:44 +02:00
|
|
|
{0,1,2}
|
|
|
|
---------------
|
|
|
|
[0:2]={0,1,2}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
2003-08-18 01:43:27 +02:00
|
|
|
SELECT ARRAY[1,2] || ARRAY[3,4] AS "{1,2,3,4}";
|
|
|
|
{1,2,3,4}
|
|
|
|
-----------
|
|
|
|
{1,2,3,4}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[[['hello','world']]] || ARRAY[[['happy','birthday']]] AS "ARRAY";
|
2003-08-18 01:43:27 +02:00
|
|
|
ARRAY
|
|
|
|
--------------------------------------
|
|
|
|
{{{hello,world}},{{happy,birthday}}}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[[1,2],[3,4]] || ARRAY[5,6] AS "{{1,2},{3,4},{5,6}}";
|
|
|
|
{{1,2},{3,4},{5,6}}
|
|
|
|
---------------------
|
|
|
|
{{1,2},{3,4},{5,6}}
|
|
|
|
(1 row)
|
|
|
|
|
2003-08-18 01:43:27 +02:00
|
|
|
SELECT ARRAY[0,0] || ARRAY[1,1] || ARRAY[2,2] AS "{0,0,1,1,2,2}";
|
|
|
|
{0,0,1,1,2,2}
|
|
|
|
---------------
|
|
|
|
{0,0,1,1,2,2}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT 0 || ARRAY[1,2] || 3 AS "{0,1,2,3}";
|
2004-08-05 05:30:44 +02:00
|
|
|
{0,1,2,3}
|
|
|
|
-----------------
|
|
|
|
[0:3]={0,1,2,3}
|
2003-04-09 01:20:04 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- array casts
|
|
|
|
SELECT ARRAY[1,2,3]::text[]::int[]::float8[] AS "{1,2,3}";
|
|
|
|
{1,2,3}
|
|
|
|
---------
|
|
|
|
{1,2,3}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[1,2,3]::text[]::int[]::float8[] is of (float8[]) as "TRUE";
|
|
|
|
TRUE
|
|
|
|
------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] AS "{{a,bc},{def,hijk}}";
|
|
|
|
{{a,bc},{def,hijk}}
|
|
|
|
---------------------
|
|
|
|
{{a,bc},{def,hijk}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] is of (varchar[]) as "TRUE";
|
|
|
|
TRUE
|
|
|
|
------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}";
|
|
|
|
{{{{{{a,bb,ccc}}}}}}
|
|
|
|
----------------------
|
|
|
|
{{{{{{a,bb,ccc}}}}}}
|
|
|
|
(1 row)
|
|
|
|
|
2003-06-29 02:33:44 +02:00
|
|
|
-- scalar op any/all (array)
|
|
|
|
select 33 = any ('{1,2,3}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 33 = any ('{1,2,33}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 33 = all ('{1,2,33}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 33 >= all ('{1,2,33}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- boundary cases
|
|
|
|
select null::int >= all ('{1,2,33}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select null::int >= all ('{}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select null::int >= any ('{}');
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- cross-datatype
|
|
|
|
select 33.4 = any (array[1,2,3]);
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 33.4 > all (array[1,2,3]);
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- errors
|
|
|
|
select 33 * any ('{1,2,3}');
|
|
|
|
ERROR: op ANY/ALL (array) requires operator to yield boolean
|
|
|
|
select 33 * any (44);
|
|
|
|
ERROR: op ANY/ALL (array) requires array on right side
|
2003-06-27 02:33:26 +02:00
|
|
|
-- test indexes on arrays
|
|
|
|
create temp table arr_tbl (f1 int[] unique);
|
2003-07-19 22:20:53 +02:00
|
|
|
NOTICE: CREATE TABLE / UNIQUE will create implicit index "arr_tbl_f1_key" for table "arr_tbl"
|
2003-06-27 02:33:26 +02:00
|
|
|
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}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: duplicate key violates unique constraint "arr_tbl_f1_key"
|
2003-06-27 02:33:26 +02:00
|
|
|
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;
|
2005-04-22 23:58:32 +02:00
|
|
|
set enable_bitmapscan to off;
|
2003-06-27 02:33:26 +02:00
|
|
|
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.
|
2005-04-22 23:58:32 +02:00
|
|
|
reset enable_seqscan;
|
|
|
|
reset enable_bitmapscan;
|
2004-04-05 05:07:26 +02:00
|
|
|
-- test [not] (like|ilike) (any|all) (...)
|
|
|
|
select 'foo' like any (array['%a', '%o']); -- t
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' like any (array['%a', '%b']); -- f
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' like all (array['f%', '%o']); -- t
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' like all (array['f%', '%b']); -- f
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' not like any (array['%a', '%b']); -- t
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' not like all (array['%a', '%o']); -- f
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' ilike any (array['%A', '%O']); -- t
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'foo' ilike all (array['F%', '%O']); -- t
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
2004-08-28 21:31:29 +02:00
|
|
|
--
|
|
|
|
-- General array parser tests
|
|
|
|
--
|
|
|
|
-- none of the following should be accepted
|
|
|
|
select '{{1,{2}},{2,3}}'::text[];
|
|
|
|
ERROR: malformed array literal: "{{1,{2}},{2,3}}"
|
|
|
|
select '{{},{}}'::text[];
|
|
|
|
ERROR: malformed array literal: "{{},{}}"
|
|
|
|
select '{{1,2},\\{2,3}}'::text[];
|
|
|
|
ERROR: malformed array literal: "{{1,2},\{2,3}}"
|
|
|
|
select '{{"1 2" x},{3}}'::text[];
|
|
|
|
ERROR: malformed array literal: "{{"1 2" x},{3}}"
|
|
|
|
select '{}}'::text[];
|
|
|
|
ERROR: malformed array literal: "{}}"
|
|
|
|
select '{ }}'::text[];
|
|
|
|
ERROR: malformed array literal: "{ }}"
|
|
|
|
-- none of the above should be accepted
|
|
|
|
-- all of the following should be accepted
|
|
|
|
select '{}'::text[];
|
|
|
|
text
|
|
|
|
------
|
|
|
|
{}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '{{{1,2,3,4},{2,3,4,5}},{{3,4,5,6},{4,5,6,7}}}'::text[];
|
|
|
|
text
|
|
|
|
-----------------------------------------------
|
|
|
|
{{{1,2,3,4},{2,3,4,5}},{{3,4,5,6},{4,5,6,7}}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '{0 second ,0 second}'::interval[];
|
|
|
|
interval
|
|
|
|
---------------
|
|
|
|
{"@ 0","@ 0"}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '{ { "," } , { 3 } }'::text[];
|
|
|
|
text
|
|
|
|
-------------
|
|
|
|
{{","},{3}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select ' { { " 0 second " , 0 second } }'::text[];
|
|
|
|
text
|
|
|
|
-------------------------------
|
|
|
|
{{" 0 second ","0 second"}}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '{
|
|
|
|
0 second,
|
|
|
|
@ 1 hour @ 42 minutes @ 20 seconds
|
|
|
|
}'::interval[];
|
|
|
|
interval
|
|
|
|
------------------------------------
|
|
|
|
{"@ 0","@ 1 hour 42 mins 20 secs"}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- all of the above should be accepted
|
2005-02-28 04:45:24 +01:00
|
|
|
-- tests for array aggregates
|
|
|
|
CREATE TEMP TABLE arraggtest ( f1 INT[], f2 TEXT[][], f3 FLOAT[]);
|
|
|
|
INSERT INTO arraggtest (f1, f2, f3) VALUES
|
|
|
|
('{1,2,3,4}','{{grey,red},{blue,blue}}','{1.6, 0.0}');
|
|
|
|
INSERT INTO arraggtest (f1, f2, f3) VALUES
|
|
|
|
('{1,2,3}','{{grey,red},{grey,blue}}','{1.6}');
|
|
|
|
SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
|
|
|
|
max | min | max | min | max | min
|
|
|
|
-----------+---------+--------------------------+--------------------------+---------+-------
|
|
|
|
{1,2,3,4} | {1,2,3} | {{grey,red},{grey,blue}} | {{grey,red},{blue,blue}} | {1.6,0} | {1.6}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
INSERT INTO arraggtest (f1, f2, f3) VALUES
|
|
|
|
('{3,3,2,4,5,6}','{{white,yellow},{pink,orange}}','{2.1,3.3,1.8,1.7,1.6}');
|
|
|
|
SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
|
|
|
|
max | min | max | min | max | min
|
|
|
|
---------------+---------+--------------------------------+--------------------------+-----------------------+-------
|
|
|
|
{3,3,2,4,5,6} | {1,2,3} | {{white,yellow},{pink,orange}} | {{grey,red},{blue,blue}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
INSERT INTO arraggtest (f1, f2, f3) VALUES
|
|
|
|
('{2}','{{black,red},{green,orange}}','{1.6,2.2,2.6,0.4}');
|
|
|
|
SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
|
|
|
|
max | min | max | min | max | min
|
|
|
|
---------------+---------+--------------------------------+------------------------------+-----------------------+-------
|
|
|
|
{3,3,2,4,5,6} | {1,2,3} | {{white,yellow},{pink,orange}} | {{black,red},{green,orange}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
INSERT INTO arraggtest (f1, f2, f3) VALUES
|
|
|
|
('{4,2,6,7,8,1}','{{red},{black},{purple},{blue},{blue}}',NULL);
|
|
|
|
SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
|
|
|
|
max | min | max | min | max | min
|
|
|
|
---------------+---------+--------------------------------+------------------------------+-----------------------+-------
|
|
|
|
{4,2,6,7,8,1} | {1,2,3} | {{white,yellow},{pink,orange}} | {{black,red},{green,orange}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
INSERT INTO arraggtest (f1, f2, f3) VALUES
|
|
|
|
('{}','{{pink,white,blue,red,grey,orange}}','{2.1,1.87,1.4,2.2}');
|
|
|
|
SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
|
|
|
|
max | min | max | min | max | min
|
|
|
|
---------------+-----+--------------------------------+------------------------------+-----------------------+-------
|
|
|
|
{4,2,6,7,8,1} | {} | {{white,yellow},{pink,orange}} | {{black,red},{green,orange}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
|
|
|
|
(1 row)
|
|
|
|
|