Re: unnest

From: Eric B(dot)Ridge <ebr(at)tcdi(dot)com>
To: "John Hansen" <john(at)geeknet(dot)com(dot)au>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: unnest
Date: 2004-11-09 02:09:38
Message-ID: 6920C9B9-31F4-11D9-9C25-000A95D98B3E@tcdi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 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

In response to

  • unnest at 2004-11-05 12:09:58 from John Hansen

Responses

  • Re: unnest at 2004-11-09 03:26:49 from John Hansen

Browse pgsql-hackers by date

  From Date Subject
Next Message Gavin Sherry 2004-11-09 02:18:21 Re: unnest
Previous Message Tom Lane 2004-11-09 01:16:15 Re: server auto-restarts and ipcs