Are there any available functions for work with big integers?
I've found a module intarray, but functions from this module only work with integer, not bigint.
I miss a function for removing an item from an array. Something like the implementation of a "minus" operator in mentioned module:
int[] - int(remove entries matching right argument from array)
With the added array_remove(anyarray, anyelement), the task is simple now:
test=> SELECT array_remove('{1,3,4,3}'::bigint[], 3);
array_remove
--------------
{1,4}
Create a custom function. This one is reasonably fast:
CREATE OR REPLACE FUNCTION arr_subtract(int8[], int8[])
RETURNS int8[]
LANGUAGE sql IMMUTABLE AS
$func$
SELECT ARRAY(
SELECT a
FROM unnest($1) WITH ORDINALITY x(a, ord)
WHERE a <> ALL ($2)
ORDER BY ord
);
$func$;
Call:
SELECT arr_subtract('{3,5,6,7,8,9}':: int8[], '{3,4,8}'::int8[]);
Result:
{5,6,7,9}
Allows to remove multiple values at once.
Keeps the original order of the array.
Does not work for NULL values.
Related:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With