Craeteing sparse arrays

From: Peter Hunsberger <peter(dot)hunsberger(at)gmail(dot)com>
To: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Craeteing sparse arrays
Date: 2009-10-15 21:20:23
Message-ID: cc159a4a0910151420v37ef3bdcv7ef2d4f6250108a3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there any easy way to create sparse arrays with Postres?
Specifically, when I construct, add or aggregate data to an array, I
want to be able to specify the position within the array where the
data is placed and have any intervening positions that have not yet
been populated just marked as nulls. eg, something like

insert into foo (bar[3],[7]) values ( 'a', 'b')

would build an array

bar = { null, null, 'a', null, null, null, 'b' }

or some such thing. I suspect I'm going to have to write a function
to just find the length and append nulls until I reach the desired
position? Given that some of the arrays I will be dealing with could
potentially be 1000s of elements long that seems a bit perverse.

I'm currently using 8.3 but 8.4 solutions are also welcome. C code
not considered out of the question if it isn't a lot of work and will
make the rest of the process close to trivial...

--
Peter Hunsberger

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-10-15 21:50:47 Re: Craeteing sparse arrays
Previous Message Merlin Moncure 2009-10-15 21:01:02 Re: npgsql and postgres enum type