mirror of
https://github.com/postgres/postgres.git
synced 2025-09-09 13:09:39 +03:00
Improve expression evaluation test coverage.
Upcoming patches are revamping expression evaluation significantly. It therefore seems prudent to try to ensure that the coverage of the existing evaluation code is high. This commit adds coverage for the cases that can reasonably be tested. There's still a bunch of unreachable error messages and such, but otherwise this achieves nearly full regression test coverage (with the exception of the unused GetAttributeByNum/GetAttributeByName). Author: Andres Freund Discussion: https://postgr.es/m/20170310194021.ek4bs4bl2khxkmll@alap3.anarazel.de
This commit is contained in:
@@ -103,6 +103,26 @@ select ('{{1,2,3},{4,5,6},{7,8,9}}'::int[])[1:2][2];
|
||||
select '[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}'::int[];
|
||||
select ('[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}'::int[])[1:2][2];
|
||||
|
||||
--
|
||||
-- check subscription corner cases
|
||||
--
|
||||
-- More subscripts than MAXDIMS(6)
|
||||
SELECT ('{}'::int[])[1][2][3][4][5][6][7];
|
||||
-- NULL index yields NULL when selecting
|
||||
SELECT ('{{{1},{2},{3}},{{4},{5},{6}}}'::int[])[1][NULL][1];
|
||||
SELECT ('{{{1},{2},{3}},{{4},{5},{6}}}'::int[])[1][NULL:1][1];
|
||||
SELECT ('{{{1},{2},{3}},{{4},{5},{6}}}'::int[])[1][1:NULL][1];
|
||||
-- NULL index in assignment is an error
|
||||
UPDATE arrtest
|
||||
SET c[NULL] = '{"can''t assign"}'
|
||||
WHERE array_dims(c) is not null;
|
||||
UPDATE arrtest
|
||||
SET c[NULL:1] = '{"can''t assign"}'
|
||||
WHERE array_dims(c) is not null;
|
||||
UPDATE arrtest
|
||||
SET c[1:NULL] = '{"can''t assign"}'
|
||||
WHERE array_dims(c) is not null;
|
||||
|
||||
-- test slices with empty lower and/or upper index
|
||||
CREATE TEMP TABLE arrtest_s (
|
||||
a int2[],
|
||||
@@ -134,6 +154,16 @@ SELECT f1[0:] FROM POINT_TBL;
|
||||
SELECT f1[:1] FROM POINT_TBL;
|
||||
SELECT f1[:] FROM POINT_TBL;
|
||||
|
||||
-- subscript assignments to fixed-width result in NULL if previous value is NULL
|
||||
UPDATE point_tbl SET f1[0] = 10 WHERE f1 IS NULL RETURNING *;
|
||||
INSERT INTO point_tbl(f1[0]) VALUES(0) RETURNING *;
|
||||
-- NULL assignments get ignored
|
||||
UPDATE point_tbl SET f1[0] = NULL WHERE f1::text = '(10,10)'::point::text RETURNING *;
|
||||
-- but non-NULL subscript assignments work
|
||||
UPDATE point_tbl SET f1[0] = -10, f1[1] = -10 WHERE f1::text = '(10,10)'::point::text RETURNING *;
|
||||
-- but not to expand the range
|
||||
UPDATE point_tbl SET f1[3] = 10 WHERE f1::text = '(-10,-10)'::point::text RETURNING *;
|
||||
|
||||
--
|
||||
-- test array extension
|
||||
--
|
||||
@@ -316,6 +346,7 @@ SELECT ARRAY[1,2,3]::text[]::int[]::float8[] is of (float8[]) as "TRUE";
|
||||
SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] AS "{{a,bc},{def,hijk}}";
|
||||
SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] is of (varchar[]) as "TRUE";
|
||||
SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}";
|
||||
SELECT NULL::text[]::int[] AS "NULL";
|
||||
|
||||
-- scalar op any/all (array)
|
||||
select 33 = any ('{1,2,3}');
|
||||
@@ -341,6 +372,8 @@ select 33 = all (null::int[]);
|
||||
select null::int = all ('{1,2,3}');
|
||||
select 33 = all ('{1,null,3}');
|
||||
select 33 = all ('{33,null,33}');
|
||||
-- nulls later in the bitmap
|
||||
SELECT -1 != ALL(ARRAY(SELECT NULLIF(g.i, 900) FROM generate_series(1,1000) g(i)));
|
||||
|
||||
-- test indexes on arrays
|
||||
create temp table arr_tbl (f1 int[] unique);
|
||||
|
Reference in New Issue
Block a user