mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
Support expressions of the form 'scalar op ANY (array)' and
'scalar op ALL (array)', where the operator is applied between the lefthand scalar and each element of the array. The operator must yield boolean; the result of the construct is the OR or AND of the per-element results, respectively. Original coding by Joe Conway, after an idea of Peter's. Rewritten by Tom to keep the implementation strictly separate from subqueries.
This commit is contained in:
@@ -294,6 +294,68 @@ SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}"
|
||||
{{{{{{a,bb,ccc}}}}}}
|
||||
(1 row)
|
||||
|
||||
-- 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
|
||||
-- test indexes on arrays
|
||||
create temp table arr_tbl (f1 int[] unique);
|
||||
NOTICE: CREATE TABLE / UNIQUE will create implicit index 'arr_tbl_f1_key' for table 'arr_tbl'
|
||||
|
||||
@@ -154,6 +154,22 @@ 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}}}}}}";
|
||||
|
||||
-- scalar op any/all (array)
|
||||
select 33 = any ('{1,2,3}');
|
||||
select 33 = any ('{1,2,33}');
|
||||
select 33 = all ('{1,2,33}');
|
||||
select 33 >= all ('{1,2,33}');
|
||||
-- boundary cases
|
||||
select null::int >= all ('{1,2,33}');
|
||||
select null::int >= all ('{}');
|
||||
select null::int >= any ('{}');
|
||||
-- cross-datatype
|
||||
select 33.4 = any (array[1,2,3]);
|
||||
select 33.4 > all (array[1,2,3]);
|
||||
-- errors
|
||||
select 33 * any ('{1,2,3}');
|
||||
select 33 * any (44);
|
||||
|
||||
-- test indexes on arrays
|
||||
create temp table arr_tbl (f1 int[] unique);
|
||||
insert into arr_tbl values ('{1,2,3}');
|
||||
|
||||
Reference in New Issue
Block a user