On Nov 5, 2004, at 7:09 AM, John Hansen wrote:
Attached, array -> rows iterator.
select * from unnest(array[1,2,3,4,5]);
This is really handy! But there is a problem...
The switch statement could probably be done in a different way, but there doesn't seem to be any good examples of how to return anyitem. If anyone have a better way, please let me know.
Why do you need the switch statement at all? array->elements is already an array of Datums. Won't simply returning
array->elements[array->i]
work?
The problem is: test=# select * from unnest('{1,2,3,4,5}'::int8[]); unnest ---------- 25314880 25314888 25314896 25314904 25314912 (5 rows)
Whereas simply returning the current Datum in array->elements returns the correct result:
if (array->i < array->num_elements) SRF_RETURN_NEXT(funcctx,array->elements[array->i++]); else SRF_RETURN_DONE(funcctx);
test=# select * from unnest('{1,2,3,4,5}'::int8[]); unnest -------- 1 2 3 4 5 (5 rows)
Also works for the few other datatypes I checked.
Am I missing something obvious?
eric
---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings