Re: Array with a lower bound>1, PostgreSQL 8.3.6

Thomas Jacob <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Tue, 2009-02-24 at 16:36 +0100, Karsten Hilbert wrote:
> On Tue, Feb 24, 2009 at 02:22:34PM +0100, Thomas Jacob wrote:
> 
> > I was wondering if there are any plans to properly support arrays with a
> > lower bound greater than one:
> 
> Well, we may first need to get the semantics straight.
> 
> If the lower bound isn't "natural" (as in 0 or 1, whatever
> seems natural to the problem at hand) it becomes arbitrary -
> a label rather than an index. In those weird cases where the
> label seems to be an index it really just stands for the
> real index (label "100" == real index at offset 100).

It really isn't all that arbitrary, AFAIK you need to have a consecutive
sequence of integer indices, the only "optimization" ist that they don't
have to start at position 1 (which would be 0 in a Python array), but
can start anywhere, including at negative numbers, so there
is no support for true sparse arrays in PostgreSQL (yet ;).

This seems to be preclude using python lists in general anyway, sorry
for not checking this before my post.

> Given arbitrary labels we don't speak about mapping
> PostgreSQL arrays to Python lists-of-lists anymore, I would
> therefore suggest mapping non-"natural" arrays to ordered
> (?) dicts-of-dicts with integer keys.

That would probably be easiest and most memory efficient, but
I think it would also be bit awkward to have different to get different
types depending on the value of the column, and it would probably
break old code.

Would it be possible to have a configurable type adaptor 
(don't really what those are yet), so that people could choose
which behavior they want? Lists or dicts of dicts?

    Thomas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.