From: | "Florian G(dot) Pflug" <fgp(at)phlo(dot)org> |
---|---|
To: | Erin Sheldon <erin(dot)sheldon(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Changing array subscripting to zero-offset |
Date: | 2006-06-18 21:01:01 |
Message-ID: | 4495BF0D.5080400@phlo.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Erin Sheldon wrote:
> Hello everyone -
>
> Array columns are, by default, 1-offset in their
> subscripting. Since I usually call postgres
> from a language with zero-offset, I would prefer
> that postgres conform to that. The online
> documentation hints that this may be configurable
> but I haven't been able to find how this is done.
Actuall, postgresql arrays can "start" (and "end", of course) at
arbitrary offsets. You could, e.g., have an array that his elements
for subscripts from -5 to 5. Thats why the functions array_upper
and array_lower exist - otherwise, it would be sufficient to have
array_length.
But you're right that postgres "defaults" to offset 1 in the sense that
all predefined functions that generate arrays return arrays with offset 1.
I'm not aware of a way to change that, but you could replace or wrap
those functions with versions that return "offset 0" arrays. I'm not
sure if it's worth the effort, though, since you're app (or it's db
abstraction layer) will need to converts arrays between a "native"
representations and a "sql" representation anyway. You could just do the
mapping there..
greetings, Florian Pflug
From | Date | Subject | |
---|---|---|---|
Next Message | canfieldsteve | 2006-06-18 22:02:05 | getting comment about constraint |
Previous Message | Erin Sheldon | 2006-06-18 19:52:04 | Changing array subscripting to zero-offset |