Re: Disallow arrays with non-standard lower bounds - Mailing list pgsql-hackers

From Florian Pflug
Subject Re: Disallow arrays with non-standard lower bounds
Date
Msg-id 838EE4F9-994E-4107-B4FF-6484E64FC6BE@phlo.org
Whole thread Raw
In response to Re: Disallow arrays with non-standard lower bounds  (Kevin Grittner <kgrittn@ymail.com>)
List pgsql-hackers
On Jan14, 2014, at 02:10 , Kevin Grittner <kgrittn@ymail.com> wrote:
> The fact that some
> day some new programmer might not be aware of all business rules,
> or might choose to try to ignore them is the reason you add
> constraints to columns and domains.

Well, for columns and domains that seems easy. We could have
 array_has_shape(value anyarray, variadic bounds int4range[])

and
 array_has_shape(value anyarray, variadic bounds int4[])

The first returns true if the value has length(bounds) dimensions
and each dimension's bounds match the corresponding range's bound,
where NULL means "arbitrary". The second one requires all lower
bounds to be 1, and checks the upper bounds against the bounds array.

Checking that an array is one-dimensional with lower bound 1 is then
accomplished by
 array_has_shape(myarray, int4range(1, NULL))

or simply
 array_has_shape(myarray, NULL);

best regards,
Florian Pflug




pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Capturing EXPLAIN ANALYZE for a query without discarding the normal result set
Next
From: Michael Paquier
Date:
Subject: Soften pg_[start|stop]_backup to allow them on a standby?