you should use something similar to 'merge sort' if your subjects (numbers) are not going beyond a certain limit eg(65535) For my application, there will likely be no more than 20 elements in the array, so practical limits are not a problem. you can generate a poly for array B's roots, and calculate A's points Can anyone point me to documentation on the performance differences between plpgsql/plc/plperl/etc? I googled but only found a few offhanded comments from mailing list archives and online message boards. Are there any general guidelines on when it's a good idea to switch to a language other than plsql or plpsql? Here's my modified version of Nagy's function. This one allows unsorted array elements, ordering the tests by the order of the elements in the first array parameter. Please forgive the lack of grace. I'd love tips on how to improve this! In particular, is there a better way to find the length of an array without having to piecewise handle the empty array case? create or replace function m_bx(a integer[],b integer[]) returns boolean[] AS $BODY$ declare res boolean[]; declare i integer; declare j integer; declare la integer; declare lb integer; begin i=1; j=1; -- array_upper returns NULL if the length of the array is 0, the following hacks provided the desired result for empty array cases -- la=array_upper(a,1); la = (select CASE WHEN count is null THEN 0 ELSE count END from (select array_upper(a::int[], 1) as count) as foo); -- lb=array_upper(b,1); lb = (select CASE WHEN count is null THEN 0 ELSE count END from (select array_upper(b::int[], 1) as count) as foo); loop if i>la then exit; end if; if (j>lb) then res[i]=false; j=1; i=i+1; else if (a[i] = b[j]) then --b contains this element, move to the next res[i]=true; j=1; i=i+1; else j=j+1; end if; end if; end loop; return res; end; $BODY$ LANGUAGE 'plpgsql' IMMUTABLE COST 100; --Test cases to handle: select m_bx('{1,2,5,4}','{5, 1, 4}'); --{t,f,t,t} select m_bx('{1,2,5,4}','{5}'); --{f,f,t,f} select m_bx('{1,2,5,4}','{}'); --{f,f,f,f} select m_bx('{}'::int[],'{}'); --{}::bool Regards, Joshua Berry On May 18, 2009, at 10:00 PM, Nagy Zoltan wrote:
|