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