Craeteing sparse arrays - Mailing list pgsql-general

From Peter Hunsberger
Subject Craeteing sparse arrays
Date
Msg-id cc159a4a0910151420v37ef3bdcv7ef2d4f6250108a3@mail.gmail.com
Whole thread Raw
Responses Re: Craeteing sparse arrays
List 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

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: npgsql and postgres enum type
Next
From: Tom Lane
Date:
Subject: Re: Craeteing sparse arrays