Обсуждение: plpgsql : looping over multidimensional array : getting NULL for subdimension
Hi all,
I'm trying to loop over a multidimensional array and find if any of the elements in a sub-dimensional array are matching some known criteria but facing issue with NULL for the sub arrays.
I have a data structure that looks like:
some_array VARCHAR[][] := '{{samba,sarath,sreenivas},{samba,mukhesh,pavan}}';
I'm trying to assign the individual sub arrays to other array elements like:
other-array VARCHAR[];
other_array=some_array[1];
and I'm expecting to get '{samba,sarath,sreenivas}' for index 1 and {samba,mukhesh,pavan} for index 2;
however, I'm getting NULL.
Can some one explain the way I can assign subarrays to other array elements plpgsql?
Thanks and Regards,
Samba
I'm trying to loop over a multidimensional array and find if any of the elements in a sub-dimensional array are matching some known criteria but facing issue with NULL for the sub arrays.
I have a data structure that looks like:
some_array VARCHAR[][] := '{{samba,sarath,sreenivas},{samba,mukhesh,pavan}}';
I'm trying to assign the individual sub arrays to other array elements like:
other-array VARCHAR[];
other_array=some_array[1];
and I'm expecting to get '{samba,sarath,sreenivas}' for index 1 and {samba,mukhesh,pavan} for index 2;
however, I'm getting NULL.
Can some one explain the way I can assign subarrays to other array elements plpgsql?
Thanks and Regards,
Samba
plpgsql : looping over multidimensional array : getting NULL for subdimension
От
Vinicio Nocciolini
Дата:
Use array_upper(aList, 2); see the example, maybe can help u CREATE OR REPLACE FUNCTION xxx( aList varchar[][]) returns TEXT as ' declare myUpper1 integer; myUpper2 integer; myRet varchar := ''''; begin myUpper1 := array_upper(aList, 1); IF myUpper1 IS NULL THEN myUpper1 := 0; END IF; myUpper2 := array_upper(aList, 2); IF myUpper2 IS NULL THEN myUpper2 := 0; END IF; FOR i in 1 .. myUpper1 LOOP FOR k in 1 .. myUpper2 LOOP myRet := myRet || aList[i][k]; END LOOP; myRet := myRet || ''_''; END LOOP; RETURN myRet; end; ' LANGUAGE 'plpgsql';