Re: array_length(anyarray) - Mailing list pgsql-hackers

From Marko Tiikkaja
Subject Re: array_length(anyarray)
Date
Msg-id 52B215DE.40409@joh.to
Whole thread Raw
In response to Re: array_length(anyarray)  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: array_length(anyarray)
List 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 by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: array_length(anyarray)
Next
From: Greg Stark
Date:
Subject: Re: Extension Templates S03E11