-- bigistore functions should find keys with exists;
SELECT exist('1=>1'::bigistore, 1);
SELECT exist('1=>1'::bigistore, 2);
SELECT exist('1=>1, -1=>0'::bigistore, 2);
SELECT exist('1=>1, -1=>0'::bigistore, -1);
-- bigistore functions should fetchvals;
SELECT fetchval('1=>1'::bigistore, 1);
SELECT fetchval('2=>1'::bigistore, 1);
SELECT fetchval('1=>1, 1=>1'::bigistore, 1);
SELECT fetchval('1=>1, 1=>1'::bigistore, 2);
-- bigistore functions should return set of ints;
SELECT * FROM each('1=>1'::bigistore);
SELECT * FROM each('5=>11, 4=>8'::bigistore);
SELECT * FROM each('5=>-411, 4=>8'::bigistore);
SELECT value + 100 FROM each('5=>-411, 4=>8'::bigistore);
SELECT * FROM each('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
SELECT * FROM each(NULL::bigistore);
-- bigistore functions should compact istores;
SELECT compact('0=>2, 1=>2, 3=>0 ,2=>2'::bigistore);
-- bigistore functions should add istores;
SELECT add('1=>1, 2=>1'::bigistore, '1=>1, 2=>1'::bigistore);
SELECT add('1=>1, 2=>1'::bigistore, '-1=>1, 2=>1'::bigistore);
SELECT add('1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT add('-1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT add('-1=>-1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT add('-1=>-1, 2=>1'::bigistore, 1);
SELECT add('-1=>-1, 2=>1'::bigistore, -1);
SELECT add('-1=>-1, 2=>1'::bigistore, 0);
SELECT add(bigistore(Array[]::integer[], Array[]::integer[]), '1=>0'::bigistore);
-- bigistore functions should substract istores;
SELECT subtract('1=>1, 2=>1'::bigistore, '1=>1, 2=>1'::bigistore);
SELECT subtract('1=>1, 2=>1'::bigistore, '-1=>1, 2=>1'::bigistore);
SELECT subtract('1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT subtract('-1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT subtract('-1=>-1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT subtract('-1=>-1, 2=>1'::bigistore, 1);
SELECT subtract('-1=>-1, 2=>1'::bigistore, -1);
SELECT subtract('-1=>-1, 2=>1'::bigistore, 0);
SELECT subtract(bigistore(Array[]::integer[], Array[]::integer[]), '1=>0'::bigistore);
-- bigistore functions should multiply istores;
SELECT multiply('1=>1, 2=>1'::bigistore, '1=>1, 2=>1'::bigistore);
SELECT multiply('1=>1, 2=>1'::bigistore, '-1=>1, 2=>1'::bigistore);
SELECT multiply('1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT multiply('-1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT multiply('-1=>-1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT multiply('-1=>-1, 2=>1'::bigistore, 1);
SELECT multiply('-1=>-1, 2=>1'::bigistore, -1);
SELECT multiply('-1=>-1, 2=>1'::bigistore, 0);
-- bigistore functions should divide istores;
SELECT divide('1=>1, 2=>1'::bigistore, '1=>1, 2=>1'::bigistore);
SELECT divide('1=>1, 2=>1'::bigistore, '-1=>1, 2=>1'::bigistore);
SELECT divide('1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT divide('-1=>1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT divide('-1=>-1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT divide('-1=>-1, 2=>1'::bigistore, '-1=>-1, 2=>1'::bigistore);
SELECT divide('1=>0, 2=>1'::bigistore, '1=>-1, 2=>1'::bigistore);
SELECT divide('1=>1, 2=>1'::bigistore, '1=>-1, 2=>1, 3=>0'::bigistore);
SELECT divide('1=>1, 2=>1'::bigistore, '3=>0'::bigistore);
SELECT divide('-1=>-1, 2=>1'::bigistore, -1);
-- bigistore functions should raise division by zero error;
SELECT divide('-1=>-1, 2=>1'::bigistore, 0);
-- bigistore functions should raise division by zero error;
SELECT divide('-1=>-1, 2=>1'::bigistore, '2=>0');
-- bigistore functions should generate #{type} from array;
SELECT bigistore(ARRAY[1]);
SELECT bigistore(ARRAY[1,1,1,1]);
SELECT bigistore(NULL);
SELECT bigistore(ARRAY[1,2,3,4]);
SELECT bigistore(ARRAY[1,2,3,4,1,2,3,4]);
SELECT bigistore(ARRAY[1,2,3,4,1,2,3,NULL]);
SELECT bigistore(ARRAY[NULL,2,3,4,1,2,3,4]);
SELECT bigistore(ARRAY[NULL,2,3,4,1,2,3,NULL]);
SELECT bigistore(ARRAY[1,2,3,NULL,1,NULL,3,4,1,2,3]);
SELECT bigistore(ARRAY[NULL,NULL,NULL,NULL]::integer[]);
SELECT bigistore(ARRAY[]::integer[]);
-- bigistore functions should sum up istores;
SELECT sum_up('1=>1'::bigistore);
SELECT sum_up(NULL::bigistore);
SELECT sum_up('1=>1, 2=>1'::bigistore);
SELECT sum_up('1=>1, 5=>1, 3=> 4'::bigistore, 3);
SELECT sum_up('1=>1 ,2=>-1, 1=>1'::bigistore);
-- bigistore functions should sum istores from table;
CREATE TABLE test1 (a bigistore);
INSERT INTO test1 VALUES('1=>1'),('2=>1'), ('3=>1');
SELECT SUM(a) FROM test1;
-- bigistore functions should sum istores from table;
CREATE TABLE test2 (a bigistore);
INSERT INTO test2 VALUES('1=>1'),('2=>1'),('3=>1'),(NULL),('3=>3');
SELECT SUM(a) FROM test2;
-- bigistore functions should sum istores from table;
CREATE TABLE test3 (a bigistore);
INSERT INTO test3 VALUES('1=>1'),('2=>1'),('3=>1'),(NULL),('3=>0');
SELECT SUM(a) FROM test3;
-- bigistore functions should merge correctly scatter keys;
SELECT SUM(x) FROM (VALUES ('1=>1, 5=>5'::istore), ('3=>3, 7=>7')) as v(x);
SELECT SUM(x) FROM (VALUES ('3=>3, 7=>7'::istore), ('1=>1, 5=>5')) as v(x);
SELECT SUM(x) FROM (VALUES ('1=>1, 5=>5'::bigistore), ('3=>3, 7=>7')) as v(x);
SELECT SUM(x) FROM (VALUES ('3=>3, 7=>7'::bigistore), ('1=>1, 5=>5')) as v(x);
-- bigistore functions should return istores from arrays;
SELECT bigistore(Array[5,3,4,5], Array[1,2,3,4]);
SELECT bigistore(Array[5,3,4,5], Array[1,2,3,4]);
SELECT bigistore(Array[5,3,4,5], Array[4000,2,4000,4]);
SELECT bigistore(Array[5,3,4]::int[], Array[5000000000,4000000000,5]::bigint[]);
-- bigistore functions should fill gaps;
SELECT fill_gaps('2=>17, 4=>3'::bigistore, 5, 0);
SELECT fill_gaps('2=>17, 4=>3'::bigistore, 5);
SELECT fill_gaps('2=>17, 4=>3'::bigistore, 3, 11);
SELECT fill_gaps('2=>17, 4=>3'::bigistore, 0, 0);
SELECT fill_gaps('2=>17'::bigistore, 3, NULL);
SELECT fill_gaps('2=>0, 3=>3'::bigistore, 3, 0);
SELECT fill_gaps(''::bigistore, 3, 0);
SELECT fill_gaps(''::bigistore, 3, 400);
SELECT fill_gaps(NULL::bigistore, 3, 0);
SELECT fill_gaps('2=>17, 4=>3'::bigistore, -5, 0);
-- bigistore functions should fill accumulate;
SELECT accumulate('2=>17, 4=>3'::bigistore);
SELECT accumulate('2=>0, 4=>3'::bigistore);
SELECT accumulate('1=>3, 2=>0, 4=>3, 6=>2'::bigistore);
SELECT accumulate(''::bigistore);
SELECT accumulate('10=>5'::bigistore);
SELECT accumulate(NULL::bigistore);
SELECT accumulate('-20=> 5, -10=> 5'::bigistore);
SELECT accumulate('-5=> 5, 3=> 5'::bigistore);
-- bigistore functions should fill accumulate upto;
SELECT accumulate('2=>17, 4=>3'::bigistore, 8);
SELECT accumulate('2=>0, 4=>3'::bigistore, 8);
SELECT accumulate('1=>3, 2=>0, 4=>3, 6=>2'::bigistore, 8);
SELECT accumulate(''::bigistore, 8);
SELECT accumulate('10=>5'::bigistore, 8);
SELECT accumulate('1=>5'::bigistore, 0);
SELECT accumulate(NULL::bigistore, 8);
SELECT accumulate('-20=> 5, -10=> 5'::bigistore, -8);
SELECT accumulate('-5=> 5, 3=> 5'::bigistore, 2);
-- bigistore functions should accumulate big numbers;
SELECT accumulate('0=>20000000000, 1=>10000000000, 3=>10000000000'::bigistore, 4);
-- bigistore functions should seed an #{type} from integer;
SELECT istore_seed(2,5,8::bigint);
SELECT istore_seed(2,5,NULL::bigint);
SELECT istore_seed(2,5,0::bigint);
SELECT istore_seed(2,2,8::bigint);
SELECT istore_seed(2,0,8::bigint);
-- bigistore functions should throw an error if negativ seed span;
SELECT istore_seed(-2,0,8);
-- bigistore functions should merge istores by larger keys;
SELECT istore_val_larger('1=>1,2=>1,3=>3'::bigistore, '1=>2,3=>1,4=>1');
-- bigistore functions should merge istores by smaller keys;
SELECT istore_val_smaller('1=>1,2=>1,3=>3'::bigistore, '1=>2,3=>1,4=>1');
-- bigistore functions should return #{type} with maxed values;
SELECT MAX(s) FROM (VALUES('1=>5, 2=>2, 3=>3'::bigistore),('1=>1, 2=>5, 3=>3'),('1=>1, 2=>4, 3=>5'))t(s);
-- bigistore functions should return #{type} with maxed values;
SELECT MIN(s) FROM (VALUES('1=>5, 2=>2, 3=>3'::bigistore),('1=>1, 2=>5, 3=>3'),('1=>1, 2=>4, 3=>5'))t(s);
-- bigistore functions should return keys as array;
SELECT akeys('-5=>10, 0=>-5, 5=>0'::bigistore);
SELECT akeys(''::bigistore);
-- bigistore functions should return values as array;
SELECT avals('-5=>10, 0=>-5, 5=>0'::bigistore);
SELECT avals(''::bigistore);
-- bigistore functions should return keys as set;
SELECT skeys('-5=>10, 0=>-5, 5=>0'::bigistore);
SELECT skeys(''::bigistore);
-- bigistore functions should return values set array;
SELECT svals('-5=>10, 0=>-5, 5=>0'::bigistore);
SELECT svals(''::bigistore);
-- bigistore functions should sum up istores;
SELECT sum_up('10=>5, 15=>10'::istore);
-- bigistore functions should sum up istores with big numbers;
SELECT sum_up('10=>2000000000, 15=>1000000000'::istore);
-- bigistore functions should sum up bigistores;
SELECT sum_up('10=>5, 15=>10'::bigistore);
-- bigistore functions should sum up istores with negative values;
SELECT sum_up('10=>5, 15=>-10'::istore);
-- bigistore functions should sum up bigistores with negative values;
SELECT sum_up('10=>5, 15=>-10'::bigistore);
-- bigistore functions should return length of empty istores;
SELECT istore_length(bigistore(ARRAY[]::integer[],ARRAY[]::integer[]));
-- bigistore functions should return length of non-empty istores;
SELECT istore_length(bigistore(ARRAY[1],ARRAY[1]));
SELECT istore_length(bigistore(ARRAY[1,2,3],ARRAY[1,2,3]));
SELECT istore_length('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
-- bigistore functions should convert istore to json;
SELECT istore_to_json('5=>50, 7=>70, 9=>90'::bigistore);
SELECT istore_to_json('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
-- bigistore functions should convert istore to array;
SELECT istore_to_array('5=>50, 7=>70, 9=>90'::bigistore);
SELECT istore_to_array('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
SELECT istore_to_array(''::bigistore);
-- bigistore functions should convert istore to matrix;
SELECT istore_to_matrix('5=>50, 7=>70, 9=>90'::bigistore);
SELECT istore_to_matrix('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
-- bigistore functions should be able to find the smallest key;
SELECT min_key(''::bigistore);
SELECT min_key('1=>1'::bigistore);
SELECT min_key('1=>1, 2=>1'::bigistore);
SELECT min_key('0=>2, 1=>2, 3=>0 ,2=>2'::bigistore);
-- bigistore functions should be able to find the biggest key;
SELECT max_key(''::bigistore);
SELECT max_key('1=>1'::bigistore);
SELECT max_key('1=>1, 2=>1'::bigistore);
SELECT max_key('0=>2, 1=>2, 3=>0 ,2=>2'::bigistore);
-- bigistore functions slice should return a partial istore;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore, ARRAY[3,5,1,9,11]);
SELECT slice('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, ARRAY[10,0]);
-- bigistore functions slice should return empty istore if no key match;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore, ARRAY[30,50,10,90]);
-- bigistore functions slice_min_max should return a partial istore;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore, 3,6);
SELECT slice('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, 0,10);
-- bigistore functions slice_min_max should return empty istore if no key match;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore,10,90);
-- bigistore functions slice_array should return a values from istore;
SELECT slice_array('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore, ARRAY[3,5,1,9,11]);
SELECT slice_array('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, ARRAY[10,0]);
-- bigistore functions slice_array should return null array if no key match;
SELECT slice_array('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore, ARRAY[30,50,10,90]);
-- bigistore functions delete should delete a key from istore;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore,3);
SELECT delete('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, 10);
-- bigistore functions delete should return istore if key unmatched;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore,6);
-- bigistore functions delete should delete multiple keys from istore;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore,ARRAY[7,8,2,5,4]);
SELECT delete('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, ARRAY[0,10,-10]);
-- bigistore functions delete should return istore if keys are unmatched;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::bigistore,ARRAY[8,6]);
-- bigistore functions delete should delete istore from istore;
SELECT delete('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, '0=>5, 10=>100');
-- bigistore functions existence should check presence of a key;
SELECT exist('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, 10);
SELECT exist('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, 25);
-- bigistore functions existence should check presence of any key;
SELECT exists_any('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, Array[10,0]);
SELECT exists_any('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, Array[27,25]);
SELECT exists_any('1=>4,2=>5'::bigistore, ARRAY[]::int[]);
-- bigistore functions existence should check presence of all key;
SELECT exists_all('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, Array[10,0]);
SELECT exists_all('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, Array[10,25]);
SELECT exists_all('1=>4,2=>5'::bigistore, ARRAY[1,3]);
SELECT exists_all('1=>4,2=>5'::bigistore, ARRAY[]::int[]);
-- bigistore functions clamp should clamp keys that are below a specified threshold;
SELECT clamp_below('1=>1'::bigistore, 0);
SELECT clamp_below('-2=>1, -1=>1, 1=>1'::bigistore, 1);
SELECT clamp_below('-2=>1, -1=>1, 1=>1'::bigistore, 0);
SELECT clamp_below('-5=>1, -1=>1, 0=>0, 1=>1'::bigistore, 0);
SELECT clamp_below('-5=>1, -1=>1, 0=>1, 1=>1'::bigistore, 0);
SELECT clamp_below('-5=>1, -1=>1, 0=>1, 1=>1'::bigistore, 2);
SELECT clamp_below('1=>1, 2=>2147483647, 3=>42'::bigistore, 2);
SELECT clamp_below('1=>1, 2=>9223372036854775807, 3=>42'::bigistore, 2);
-- bigistore functions clamp should clamp keys that are above a specified threshold;
SELECT clamp_above('1=>1'::bigistore, 2);
SELECT clamp_above('-1=>1, 1=>1, 2=>1'::bigistore, -1);
SELECT clamp_above('-1=>1, 1=>1, 2=>1'::bigistore, 0);
SELECT clamp_above('-1=>1, 0=>0, 1=>1, 2=>1'::bigistore, 0);
SELECT clamp_above('-1=>1, 0=>1, 1=>1, 2=>1'::bigistore, 0);
SELECT clamp_above('-1=>1, 0=>1, 1=>1, 2=>1'::bigistore, -6);
-- bigistore functions concat should concat two istores;
SELECT concat('1=>4, 2=>5'::bigistore, '3=>4, 2=>7'::bigistore);
SELECT concat('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, '-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
-- bigistore functions concat should concat empty istores;
SELECT concat('-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore, ''::bigistore);
SELECT concat(''::bigistore, '-2147483647 => 10, -10 => -9223372036854775807, 0 => 5, 10 => 9223372036854775806, 2147483647 => 10'::bigistore);
SELECT concat(''::bigistore, ''::bigistore);
-- bigistore functions istore_in_range shoud return true iff istore is in the given range;
SELECT istore_in_range('1=>-32768, 2 => 0, 3=>32767'::bigistore, -32768, 32767);
SELECT istore_in_range('1=>10, 2=>-1, 3=>5'::bigistore, -1, 10);
SELECT istore_in_range('1=>0, 2=>1, 3=>2'::bigistore, 3, -1);
-- bigistore functions istore_in_range should handle corner cases correctly;
SELECT istore_in_range(''::bigistore, -1, 1);
SELECT istore_in_range('-5=>0, 1=>0'::bigistore, 0, 0);
SELECT istore_in_range('1=>2, 3=>4'::bigistore, 5, 0);
-- bigistore functions istore_less_than, istore_greater_than, istore_less_than_or_equal, istore_greater_than_or_equal should also work with less than and greater than (or equal);
SELECT istore_less_than('1=>100, 2=>-100'::bigistore, 100);
SELECT istore_less_than_or_equal('1=>100, 2=>-100'::bigistore, 100);
SELECT istore_greater_than('1=>100, 2=>-100'::bigistore, -100);
SELECT istore_greater_than_or_equal('1=>100, 2=>-100'::bigistore, -100);
-- bigistore functions istore_floor, istore_ceiling should accept corner cases;
SELECT istore_ceiling(''::bigistore, 0);
SELECT istore_floor(''::bigistore, 0);
-- bigistore functions istore_floor, istore_ceiling should filter out values based on floor and ceiling;
SELECT istore_floor('1=>-32768, -1=>32767'::bigistore, -32767);
SELECT istore_ceiling('1=>-32768, -1=>32767'::bigistore, 32766);
SELECT istore_floor('1=>1, 2=>2, 3=>3, 4=>4, 5=>5'::bigistore, 3);
SELECT istore_ceiling('1=>1, 2=>2, 3=>3, 4=>4, 5=>5'::bigistore, 3);
-- istore functions should find keys with exists;
SELECT exist('1=>1'::istore, 1);
SELECT exist('1=>1'::istore, 2);
SELECT exist('1=>1, -1=>0'::istore, 2);
SELECT exist('1=>1, -1=>0'::istore, -1);
-- istore functions should fetchvals;
SELECT fetchval('1=>1'::istore, 1);
SELECT fetchval('2=>1'::istore, 1);
SELECT fetchval('1=>1, 1=>1'::istore, 1);
SELECT fetchval('1=>1, 1=>1'::istore, 2);
-- istore functions should return set of ints;
SELECT * FROM each('1=>1'::istore);
SELECT * FROM each('5=>11, 4=>8'::istore);
SELECT * FROM each('5=>-411, 4=>8'::istore);
SELECT value + 100 FROM each('5=>-411, 4=>8'::istore);
SELECT * FROM each('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
SELECT * FROM each(NULL::istore);
-- istore functions should compact istores;
SELECT compact('0=>2, 1=>2, 3=>0 ,2=>2'::istore);
-- istore functions should add istores;
SELECT add('1=>1, 2=>1'::istore, '1=>1, 2=>1'::istore);
SELECT add('1=>1, 2=>1'::istore, '-1=>1, 2=>1'::istore);
SELECT add('1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT add('-1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT add('-1=>-1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT add('-1=>-1, 2=>1'::istore, 1);
SELECT add('-1=>-1, 2=>1'::istore, -1);
SELECT add('-1=>-1, 2=>1'::istore, 0);
SELECT add(istore(Array[]::integer[], Array[]::integer[]), '1=>0'::istore);
-- istore functions should substract istores;
SELECT subtract('1=>1, 2=>1'::istore, '1=>1, 2=>1'::istore);
SELECT subtract('1=>1, 2=>1'::istore, '-1=>1, 2=>1'::istore);
SELECT subtract('1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT subtract('-1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT subtract('-1=>-1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT subtract('-1=>-1, 2=>1'::istore, 1);
SELECT subtract('-1=>-1, 2=>1'::istore, -1);
SELECT subtract('-1=>-1, 2=>1'::istore, 0);
SELECT subtract(istore(Array[]::integer[], Array[]::integer[]), '1=>0'::istore);
-- istore functions should multiply istores;
SELECT multiply('1=>1, 2=>1'::istore, '1=>1, 2=>1'::istore);
SELECT multiply('1=>1, 2=>1'::istore, '-1=>1, 2=>1'::istore);
SELECT multiply('1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT multiply('-1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT multiply('-1=>-1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT multiply('-1=>-1, 2=>1'::istore, 1);
SELECT multiply('-1=>-1, 2=>1'::istore, -1);
SELECT multiply('-1=>-1, 2=>1'::istore, 0);
-- istore functions should divide istores;
SELECT divide('1=>1, 2=>1'::istore, '1=>1, 2=>1'::istore);
SELECT divide('1=>1, 2=>1'::istore, '-1=>1, 2=>1'::istore);
SELECT divide('1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT divide('-1=>1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT divide('-1=>-1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT divide('-1=>-1, 2=>1'::istore, '-1=>-1, 2=>1'::istore);
SELECT divide('1=>0, 2=>1'::istore, '1=>-1, 2=>1'::istore);
SELECT divide('1=>1, 2=>1'::istore, '1=>-1, 2=>1, 3=>0'::istore);
SELECT divide('1=>1, 2=>1'::istore, '3=>0'::istore);
SELECT divide('-1=>-1, 2=>1'::istore, -1);
-- istore functions should raise division by zero error;
SELECT divide('-1=>-1, 2=>1'::istore, 0);
-- istore functions should raise division by zero error;
SELECT divide('-1=>-1, 2=>1'::istore, '2=>0');
-- istore functions should generate #{type} from array;
SELECT istore(ARRAY[1]);
SELECT istore(ARRAY[1,1,1,1]);
SELECT istore(NULL);
SELECT istore(ARRAY[1,2,3,4]);
SELECT istore(ARRAY[1,2,3,4,1,2,3,4]);
SELECT istore(ARRAY[1,2,3,4,1,2,3,NULL]);
SELECT istore(ARRAY[NULL,2,3,4,1,2,3,4]);
SELECT istore(ARRAY[NULL,2,3,4,1,2,3,NULL]);
SELECT istore(ARRAY[1,2,3,NULL,1,NULL,3,4,1,2,3]);
SELECT istore(ARRAY[NULL,NULL,NULL,NULL]::integer[]);
SELECT istore(ARRAY[]::integer[]);
-- istore functions should sum up istores;
SELECT sum_up('1=>1'::istore);
SELECT sum_up(NULL::istore);
SELECT sum_up('1=>1, 2=>1'::istore);
SELECT sum_up('1=>1, 5=>1, 3=> 4'::istore, 3);
SELECT sum_up('1=>1 ,2=>-1, 1=>1'::istore);
-- istore functions should sum istores from table;
CREATE TABLE test4 (a istore);
INSERT INTO test4 VALUES('1=>1'),('2=>1'), ('3=>1');
SELECT SUM(a) FROM test4;
-- istore functions should sum istores from table;
CREATE TABLE test5 (a istore);
INSERT INTO test5 VALUES('1=>1'),('2=>1'),('3=>1'),(NULL),('3=>3');
SELECT SUM(a) FROM test5;
-- istore functions should sum istores from table;
CREATE TABLE test6 (a istore);
INSERT INTO test6 VALUES('1=>1'),('2=>1'),('3=>1'),(NULL),('3=>0');
SELECT SUM(a) FROM test6;
-- istore functions should merge correctly scatter keys;
SELECT SUM(x) FROM (VALUES ('1=>1, 5=>5'::istore), ('3=>3, 7=>7')) as v(x);
SELECT SUM(x) FROM (VALUES ('3=>3, 7=>7'::istore), ('1=>1, 5=>5')) as v(x);
SELECT SUM(x) FROM (VALUES ('1=>1, 5=>5'::bigistore), ('3=>3, 7=>7')) as v(x);
SELECT SUM(x) FROM (VALUES ('3=>3, 7=>7'::bigistore), ('1=>1, 5=>5')) as v(x);
-- istore functions should return istores from arrays;
SELECT istore(Array[5,3,4,5], Array[1,2,3,4]);
SELECT istore(Array[5,3,4,5], Array[1,2,3,4]);
SELECT istore(Array[5,3,4,5], Array[4000,2,4000,4]);
SELECT istore(Array[1,1]::int[], Array[-1,-1]::int[]);
-- istore functions should fill gaps;
SELECT fill_gaps('2=>17, 4=>3'::istore, 5, 0);
SELECT fill_gaps('2=>17, 4=>3'::istore, 5);
SELECT fill_gaps('2=>17, 4=>3'::istore, 3, 11);
SELECT fill_gaps('2=>17, 4=>3'::istore, 0, 0);
SELECT fill_gaps('2=>17'::istore, 3, NULL);
SELECT fill_gaps('2=>0, 3=>3'::istore, 3, 0);
SELECT fill_gaps(''::istore, 3, 0);
SELECT fill_gaps(''::istore, 3, 400);
SELECT fill_gaps(NULL::istore, 3, 0);
SELECT fill_gaps('2=>17, 4=>3'::istore, -5, 0);
-- istore functions should fill accumulate;
SELECT accumulate('2=>17, 4=>3'::istore);
SELECT accumulate('2=>0, 4=>3'::istore);
SELECT accumulate('1=>3, 2=>0, 4=>3, 6=>2'::istore);
SELECT accumulate(''::istore);
SELECT accumulate('10=>5'::istore);
SELECT accumulate(NULL::istore);
SELECT accumulate('-20=> 5, -10=> 5'::istore);
SELECT accumulate('-5=> 5, 3=> 5'::istore);
-- istore functions should fill accumulate upto;
SELECT accumulate('2=>17, 4=>3'::istore, 8);
SELECT accumulate('2=>0, 4=>3'::istore, 8);
SELECT accumulate('1=>3, 2=>0, 4=>3, 6=>2'::istore, 8);
SELECT accumulate(''::istore, 8);
SELECT accumulate('10=>5'::istore, 8);
SELECT accumulate('1=>5'::istore, 0);
SELECT accumulate(NULL::istore, 8);
SELECT accumulate('-20=> 5, -10=> 5'::istore, -8);
SELECT accumulate('-5=> 5, 3=> 5'::istore, 2);
-- istore functions should accumulate big numbers;
SELECT accumulate('0=>20000000000, 1=>10000000000, 3=>10000000000'::bigistore, 4);
-- istore functions should seed an #{type} from integer;
SELECT istore_seed(2,5,8::int);
SELECT istore_seed(2,5,NULL::int);
SELECT istore_seed(2,5,0::int);
SELECT istore_seed(2,2,8::int);
SELECT istore_seed(2,0,8::int);
-- istore functions should throw an error if negativ seed span;
SELECT istore_seed(-2,0,8);
-- istore functions should merge istores by larger keys;
SELECT istore_val_larger('1=>1,2=>1,3=>3'::istore, '1=>2,3=>1,4=>1');
-- istore functions should merge istores by smaller keys;
SELECT istore_val_smaller('1=>1,2=>1,3=>3'::istore, '1=>2,3=>1,4=>1');
-- istore functions should return #{type} with maxed values;
SELECT MAX(s) FROM (VALUES('1=>5, 2=>2, 3=>3'::istore),('1=>1, 2=>5, 3=>3'),('1=>1, 2=>4, 3=>5'))t(s);
-- istore functions should return #{type} with maxed values;
SELECT MIN(s) FROM (VALUES('1=>5, 2=>2, 3=>3'::istore),('1=>1, 2=>5, 3=>3'),('1=>1, 2=>4, 3=>5'))t(s);
-- istore functions should return keys as array;
SELECT akeys('-5=>10, 0=>-5, 5=>0'::istore);
SELECT akeys(''::istore);
-- istore functions should return values as array;
SELECT avals('-5=>10, 0=>-5, 5=>0'::istore);
SELECT avals(''::istore);
-- istore functions should return keys as set;
SELECT skeys('-5=>10, 0=>-5, 5=>0'::istore);
SELECT skeys(''::istore);
-- istore functions should return values set array;
SELECT svals('-5=>10, 0=>-5, 5=>0'::istore);
SELECT svals(''::istore);
-- istore functions should sum up istores;
SELECT sum_up('10=>5, 15=>10'::istore);
-- istore functions should sum up istores with big numbers;
SELECT sum_up('10=>2000000000, 15=>1000000000'::istore);
-- istore functions should sum up bigistores;
SELECT sum_up('10=>5, 15=>10'::bigistore);
-- istore functions should sum up istores with negative values;
SELECT sum_up('10=>5, 15=>-10'::istore);
-- istore functions should sum up bigistores with negative values;
SELECT sum_up('10=>5, 15=>-10'::bigistore);
-- istore functions should return length of empty istores;
SELECT istore_length(istore(ARRAY[]::integer[],ARRAY[]::integer[]));
-- istore functions should return length of non-empty istores;
SELECT istore_length(istore(ARRAY[1],ARRAY[1]));
SELECT istore_length(istore(ARRAY[1,2,3],ARRAY[1,2,3]));
SELECT istore_length('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
-- istore functions should convert istore to json;
SELECT istore_to_json('5=>50, 7=>70, 9=>90'::istore);
SELECT istore_to_json('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
-- istore functions should convert istore to array;
SELECT istore_to_array('5=>50, 7=>70, 9=>90'::istore);
SELECT istore_to_array('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
SELECT istore_to_array(''::istore);
-- istore functions should convert istore to matrix;
SELECT istore_to_matrix('5=>50, 7=>70, 9=>90'::istore);
SELECT istore_to_matrix('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
-- istore functions should be able to find the smallest key;
SELECT min_key(''::istore);
SELECT min_key('1=>1'::istore);
SELECT min_key('1=>1, 2=>1'::istore);
SELECT min_key('0=>2, 1=>2, 3=>0 ,2=>2'::istore);
-- istore functions should be able to find the biggest key;
SELECT max_key(''::istore);
SELECT max_key('1=>1'::istore);
SELECT max_key('1=>1, 2=>1'::istore);
SELECT max_key('0=>2, 1=>2, 3=>0 ,2=>2'::istore);
-- istore functions slice should return a partial istore;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore, ARRAY[3,5,1,9,11]);
SELECT slice('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, ARRAY[10,0]);
-- istore functions slice should return empty istore if no key match;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore, ARRAY[30,50,10,90]);
-- istore functions slice_min_max should return a partial istore;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore, 3,6);
SELECT slice('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, 0,10);
-- istore functions slice_min_max should return empty istore if no key match;
SELECT slice('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore,10,90);
-- istore functions slice_array should return a values from istore;
SELECT slice_array('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore, ARRAY[3,5,1,9,11]);
SELECT slice_array('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, ARRAY[10,0]);
-- istore functions slice_array should return null array if no key match;
SELECT slice_array('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore, ARRAY[30,50,10,90]);
-- istore functions delete should delete a key from istore;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore,3);
SELECT delete('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, 10);
-- istore functions delete should return istore if key unmatched;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore,6);
-- istore functions delete should delete multiple keys from istore;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore,ARRAY[7,8,2,5,4]);
SELECT delete('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, ARRAY[0,10,-10]);
-- istore functions delete should return istore if keys are unmatched;
SELECT delete('1=>10, 2=>20, 3=>30, 4=>40, 5=>50, 7=>70, 9=>90'::istore,ARRAY[8,6]);
-- istore functions delete should delete istore from istore;
SELECT delete('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, '0=>5, 10=>100');
-- istore functions existence should check presence of a key;
SELECT exist('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, 10);
SELECT exist('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, 25);
-- istore functions existence should check presence of any key;
SELECT exists_any('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, Array[10,0]);
SELECT exists_any('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, Array[27,25]);
SELECT exists_any('1=>4,2=>5'::istore, ARRAY[]::int[]);
-- istore functions existence should check presence of all key;
SELECT exists_all('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, Array[10,0]);
SELECT exists_all('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, Array[10,25]);
SELECT exists_all('1=>4,2=>5'::istore, ARRAY[1,3]);
SELECT exists_all('1=>4,2=>5'::istore, ARRAY[]::int[]);
-- istore functions clamp should clamp keys that are below a specified threshold;
SELECT clamp_below('1=>1'::istore, 0);
SELECT clamp_below('-2=>1, -1=>1, 1=>1'::istore, 1);
SELECT clamp_below('-2=>1, -1=>1, 1=>1'::istore, 0);
SELECT clamp_below('-5=>1, -1=>1, 0=>0, 1=>1'::istore, 0);
SELECT clamp_below('-5=>1, -1=>1, 0=>1, 1=>1'::istore, 0);
SELECT clamp_below('-5=>1, -1=>1, 0=>1, 1=>1'::istore, 2);
SELECT clamp_below('1=>1, 2=>2147483647, 3=>42'::istore, 2);
-- istore functions clamp should clamp keys that are above a specified threshold;
SELECT clamp_above('1=>1'::istore, 2);
SELECT clamp_above('-1=>1, 1=>1, 2=>1'::istore, -1);
SELECT clamp_above('-1=>1, 1=>1, 2=>1'::istore, 0);
SELECT clamp_above('-1=>1, 0=>0, 1=>1, 2=>1'::istore, 0);
SELECT clamp_above('-1=>1, 0=>1, 1=>1, 2=>1'::istore, 0);
SELECT clamp_above('-1=>1, 0=>1, 1=>1, 2=>1'::istore, -6);
-- istore functions concat should concat two istores;
SELECT concat('1=>4, 2=>5'::istore, '3=>4, 2=>7'::istore);
SELECT concat('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, '-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
-- istore functions concat should concat empty istores;
SELECT concat('-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore, ''::istore);
SELECT concat(''::istore, '-2147483647 => 10, -10 => -2147483647, 0 => 5, 10 => 2147483647, 2147483647 => 10'::istore);
SELECT concat(''::istore, ''::istore);
-- istore functions istore_in_range shoud return true iff istore is in the given range;
SELECT istore_in_range('1=>-32768, 2 => 0, 3=>32767'::istore, -32768, 32767);
SELECT istore_in_range('1=>10, 2=>-1, 3=>5'::istore, -1, 10);
SELECT istore_in_range('1=>0, 2=>1, 3=>2'::istore, 3, -1);
-- istore functions istore_in_range should handle corner cases correctly;
SELECT istore_in_range(''::istore, -1, 1);
SELECT istore_in_range('-5=>0, 1=>0'::istore, 0, 0);
SELECT istore_in_range('1=>2, 3=>4'::istore, 5, 0);
-- istore functions istore_less_than, istore_greater_than, istore_less_than_or_equal, istore_greater_than_or_equal should also work with less than and greater than (or equal);
SELECT istore_less_than('1=>100, 2=>-100'::istore, 100);
SELECT istore_less_than_or_equal('1=>100, 2=>-100'::istore, 100);
SELECT istore_greater_than('1=>100, 2=>-100'::istore, -100);
SELECT istore_greater_than_or_equal('1=>100, 2=>-100'::istore, -100);
-- istore functions istore_floor, istore_ceiling should accept corner cases;
SELECT istore_ceiling(''::istore, 0);
SELECT istore_floor(''::istore, 0);
-- istore functions istore_floor, istore_ceiling should filter out values based on floor and ceiling;
SELECT istore_floor('1=>-32768, -1=>32767'::istore, -32767);
SELECT istore_ceiling('1=>-32768, -1=>32767'::istore, 32766);
SELECT istore_floor('1=>1, 2=>2, 3=>3, 4=>4, 5=>5'::istore, 3);
SELECT istore_ceiling('1=>1, 2=>2, 3=>3, 4=>4, 5=>5'::istore, 3);
