mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
01783ac36d
Commit716ea626a
attempted to fix the problem of building 1-D zero-size arrays once and for all. But it turns out that contrib/intarray has some code that doesn't use construct_array() but just builds arrays by hand, so it didn't get the memo. This appears to affect all of subarray(), intset_subtract(), inner_int_union(), inner_int_inter(), and intarray_concat_arrays(). Back-patch into v11. In the past we've not back-patched this type of change, but since v11 is still in beta it seems all right to include this fix in it. Besides it's more consistent to make the fix in v11 where716ea626a
appeared. Report and patch by Alexey Kryuchkov, some cosmetic adjustments by me Report: https://postgr.es/m/153053285112.13258.434620894305716755@wrigleys.postgresql.org Discussion: https://postgr.es/m/CAN85JcYphDLYt4CpMDLZjjNVqGDrFJ5eS3YF=wLAhFoDQuBsyg@mail.gmail.com
126 lines
4.5 KiB
SQL
126 lines
4.5 KiB
SQL
CREATE EXTENSION intarray;
|
|
|
|
-- Check whether any of our opclasses fail amvalidate
|
|
SELECT amname, opcname
|
|
FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
|
|
WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
|
|
|
|
SELECT intset(1234);
|
|
SELECT icount('{1234234,234234}');
|
|
SELECT sort('{1234234,-30,234234}');
|
|
SELECT sort('{1234234,-30,234234}','asc');
|
|
SELECT sort('{1234234,-30,234234}','desc');
|
|
SELECT sort_asc('{1234234,-30,234234}');
|
|
SELECT sort_desc('{1234234,-30,234234}');
|
|
SELECT uniq('{1234234,-30,-30,234234,-30}');
|
|
SELECT uniq(sort_asc('{1234234,-30,-30,234234,-30}'));
|
|
SELECT idx('{1234234,-30,-30,234234,-30}',-30);
|
|
SELECT subarray('{1234234,-30,-30,234234,-30}',2,3);
|
|
SELECT subarray('{1234234,-30,-30,234234,-30}',-1,1);
|
|
SELECT subarray('{1234234,-30,-30,234234,-30}',0,-1);
|
|
|
|
SELECT #'{1234234,234234}'::int[];
|
|
SELECT '{123,623,445}'::int[] + 1245;
|
|
SELECT '{123,623,445}'::int[] + 445;
|
|
SELECT '{123,623,445}'::int[] + '{1245,87,445}';
|
|
SELECT '{123,623,445}'::int[] - 623;
|
|
SELECT '{123,623,445}'::int[] - '{1623,623}';
|
|
SELECT '{123,623,445}'::int[] | 623;
|
|
SELECT '{123,623,445}'::int[] | 1623;
|
|
SELECT '{123,623,445}'::int[] | '{1623,623}';
|
|
SELECT '{123,623,445}'::int[] & '{1623,623}';
|
|
SELECT '{-1,3,1}'::int[] & '{1,2}';
|
|
SELECT '{1}'::int[] & '{2}'::int[];
|
|
SELECT array_dims('{1}'::int[] & '{2}'::int[]);
|
|
SELECT ('{1}'::int[] & '{2}'::int[]) = '{}'::int[];
|
|
SELECT ('{}'::int[] & '{}'::int[]) = '{}'::int[];
|
|
|
|
|
|
--test query_int
|
|
SELECT '1'::query_int;
|
|
SELECT ' 1'::query_int;
|
|
SELECT '1 '::query_int;
|
|
SELECT ' 1 '::query_int;
|
|
SELECT ' ! 1 '::query_int;
|
|
SELECT '!1'::query_int;
|
|
SELECT '1|2'::query_int;
|
|
SELECT '1|!2'::query_int;
|
|
SELECT '!1|2'::query_int;
|
|
SELECT '!1|!2'::query_int;
|
|
SELECT '!(!1|!2)'::query_int;
|
|
SELECT '!(!1|2)'::query_int;
|
|
SELECT '!(1|!2)'::query_int;
|
|
SELECT '!(1|2)'::query_int;
|
|
SELECT '1&2'::query_int;
|
|
SELECT '!1&2'::query_int;
|
|
SELECT '1&!2'::query_int;
|
|
SELECT '!1&!2'::query_int;
|
|
SELECT '(1&2)'::query_int;
|
|
SELECT '1&(2)'::query_int;
|
|
SELECT '!(1)&2'::query_int;
|
|
SELECT '!(1&2)'::query_int;
|
|
SELECT '1|2&3'::query_int;
|
|
SELECT '1|(2&3)'::query_int;
|
|
SELECT '(1|2)&3'::query_int;
|
|
SELECT '1|2&!3'::query_int;
|
|
SELECT '1|!2&3'::query_int;
|
|
SELECT '!1|2&3'::query_int;
|
|
SELECT '!1|(2&3)'::query_int;
|
|
SELECT '!(1|2)&3'::query_int;
|
|
SELECT '(!1|2)&3'::query_int;
|
|
SELECT '1|(2|(4|(5|6)))'::query_int;
|
|
SELECT '1|2|4|5|6'::query_int;
|
|
SELECT '1&(2&(4&(5&6)))'::query_int;
|
|
SELECT '1&2&4&5&6'::query_int;
|
|
SELECT '1&(2&(4&(5|6)))'::query_int;
|
|
SELECT '1&(2&(4&(5|!6)))'::query_int;
|
|
|
|
|
|
CREATE TABLE test__int( a int[] );
|
|
\copy test__int from 'data/test__int.data'
|
|
ANALYZE test__int;
|
|
|
|
SELECT count(*) from test__int WHERE a && '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23|50';
|
|
SELECT count(*) from test__int WHERE a @> '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23&50';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}';
|
|
SELECT count(*) from test__int WHERE a @@ '50&68';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
|
|
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
|
|
|
|
CREATE INDEX text_idx on test__int using gist ( a gist__int_ops );
|
|
|
|
SELECT count(*) from test__int WHERE a && '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23|50';
|
|
SELECT count(*) from test__int WHERE a @> '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23&50';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}';
|
|
SELECT count(*) from test__int WHERE a @@ '50&68';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
|
|
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
|
|
|
|
DROP INDEX text_idx;
|
|
CREATE INDEX text_idx on test__int using gist ( a gist__intbig_ops );
|
|
|
|
SELECT count(*) from test__int WHERE a && '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23|50';
|
|
SELECT count(*) from test__int WHERE a @> '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23&50';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}';
|
|
SELECT count(*) from test__int WHERE a @@ '50&68';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
|
|
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
|
|
|
|
DROP INDEX text_idx;
|
|
CREATE INDEX text_idx on test__int using gin ( a gin__int_ops );
|
|
|
|
SELECT count(*) from test__int WHERE a && '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23|50';
|
|
SELECT count(*) from test__int WHERE a @> '{23,50}';
|
|
SELECT count(*) from test__int WHERE a @@ '23&50';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}';
|
|
SELECT count(*) from test__int WHERE a @@ '50&68';
|
|
SELECT count(*) from test__int WHERE a @> '{20,23}' or a @> '{50,68}';
|
|
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
|