Re: proposal: FOREACH-IN-ARRAY (probably for 9.2?)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: proposal: FOREACH-IN-ARRAY (probably for 9.2?)
Дата
Msg-id 463.1292601964@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: proposal: FOREACH-IN-ARRAY (probably for 9.2?)  (Merlin Moncure <mmoncure@gmail.com>)
Ответы Re: proposal: FOREACH-IN-ARRAY (probably for 9.2?)  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers
Merlin Moncure <mmoncure@gmail.com> writes:
> On Fri, Dec 17, 2010 at 10:47 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> This seems like a really bad, confusing idea. �I think it should throw
>> a type-mismatch error in this case. �If there is any use-case for such a
>> thing, which I'm quite unconvinced of, it ought to use a separate syntax
>> rather than overloading the element-by-element syntax.

> I don't agree at all -- iterating arrays by slice is a frequently
> requested feature (you can kinda sorta do it by slice notation, but
> arr[n] giving null is a -general FAQ.  This is how people think arrays
> should work.  I suppose that having this functionality reserved in a
> tiny corner of plpgsql is not so good, but I think foreach... would
> become the preferred way to iterate arrays always.

Well, okay, if it's useful we can have it, but I still say it needs to
be a separate syntax.  The example Pavel gives looks like nothing so
much as a beginner's error, ie putting [] on the target variable when
he shouldn't have.

Furthermore, it's underspecified: who's to say how many dimensions of
the array are supposed to get sliced off?  There's no reasonable place
to extend this syntax to specify that.  It will also be inconsistent
for "foreach scalar in array" to iterate element-by-element no matter
how many dimensions array has, while "foreach array in array" does
something different from that.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: bug in SignalSomeChildren
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: bug in SignalSomeChildren