Re: "select ('{}'::text[])[1]" returns NULL -- is it correct?

Поиск
Список
Период
Сортировка
От Florian G. Pflug
Тема Re: "select ('{}'::text[])[1]" returns NULL -- is it correct?
Дата
Msg-id 461BECDD.3000909@phlo.org
обсуждение исходный текст
Ответ на Re: "select ('{}'::text[])[1]" returns NULL -- is it correct?  ("Nikolay Samokhvalov" <nikolay@samokhvalov.com>)
Список pgsql-hackers
Nikolay Samokhvalov wrote:
> On 4/10/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> "Nikolay Samokhvalov" <nikolay@samokhvalov.com> writes:
>> > I remember several cases when people (e.g. me :-) ) were spending some
>> > time trying to find an error in some pl/pgsql function and the reason
>> > lied in incorrect work with arrays (i.e. messages like "index is out
>> > of bounds" and "index cannot be negative number" would help, surely).
>>
>> Well, if indexes *couldn't* be negative numbers then that might be
>> helpful, but they can.
>>
> Ooops :-) OK, my proposal is narrowing to very simple one: what about
> triggering WARNINGs when user tries to access nonexistent element of
> array?

Please don't ;-)
There are two sane options - return an error, or return NULL. Both are
sensible, and different programming languages make different choices.

The only reason for a WARNING would be a long-term plan to change the
existing behaviour. But this will cause lots of pain, for no real gain,
because no matter which behaviour you pick, there are always situations
where the other would be more convenient.

Just look at the mess PHP has created by altering fundamental aspects
of the language (4.4 -> 5.0).

greetings, Florian Pflug


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

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: [DOCS] uuid type not documented
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Anyone interested in improving postgresql scaling?