sql - Exclude matched array elements -
how can exclude matched elements of 1 array another?
postgres code:
a1 := '{1, 2, 5, 15}'::int[]; a2 := '{1, 2, 3, 6, 7, 9, 15}'::int[]; a3 := a2 ??magic_operator?? a1;
in a3
expect '{3, 6, 7, 9}'
final result
my , lad2025 solutions works fine.
solution array_position()
required postgresql 9.5 , later, executes x3 faster.
the additional module intarray
provides simple , fast subtraction operator -
integer arrays, magic_operator looking for:
test=# select '{1, 2, 3, 6, 7, 9, 15}'::int[] - '{1, 2, 5, 15}'::int[] result; ?column? ----------- {3,6,7,9}
you need install module once per database:
create extension intarray;
it provides special operator classes indexes:
note only works for:
... null-free arrays of integers.
Comments
Post a Comment