--
-- compares 2 int-arrays and returns the count of identical values
--

create or replace function array_compare(a int[], b int[]) returns int as $$
declare _tmp RECORD;
	_min	int;
	_max	int;
	_count	int;
begin
	select into _max array_upper($1,1);
	select into _min array_lower($1,1);
	_count := 0;
	for _tmp in select a[idx.i] as foo from generate_series(_min,_max) idx(i) loop
		if _tmp.foo = any($2) then
			_count := _count +1;
		end if;	
	end loop;
	return _count;
end;
$$ language plpgsql;

