Re: array_length(anyarray)

Поиск
Список
Период
Сортировка
От Marko Tiikkaja
Тема Re: array_length(anyarray)
Дата
Msg-id 52B215DE.40409@joh.to
обсуждение исходный текст
Ответ на Re: array_length(anyarray)  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: array_length(anyarray)
Список pgsql-hackers
On 2013-12-18 22:32, Andrew Dunstan wrote:
> You're not really free to assume it - you'll need an exception handler
> for the other-than-1 case, or your code might blow up.
>
> This seems to be codifying a bad pattern, which should be using
> array_lower() and array_upper() instead.

That's the entire point -- I *want* my code to blow up.  If someone 
passes a multi-dimensional array to a function that assumes its input is 
one-dimensional and its indexes start from 1, I want it to be obvious 
that the caller did something wrong.  Now I either copy-paste lines and 
lines of codes to always test for the weird cases or my code breaks in 
subtle ways.

This is no different from an Assert() somewhere -- if the caller breaks 
the documented interface, it's his problem, not mine.  And I don't want 
to waste my time coding around the fact that this simple thing is so 
hard to do in PG.



Regards,
Marko Tiikkaja



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

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: array_length(anyarray)
Следующее
От: Greg Stark
Дата:
Сообщение: Re: Extension Templates S03E11