Re: unnest
От | Eric B.Ridge |
---|---|
Тема | Re: unnest |
Дата | |
Msg-id | 6920C9B9-31F4-11D9-9C25-000A95D98B3E@tcdi.com обсуждение исходный текст |
Ответ на | unnest ("John Hansen" <john@geeknet.com.au>) |
Ответы |
Re: unnest
|
Список | pgsql-hackers |
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 returningarray->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
В списке pgsql-hackers по дате отправления: