Re: array_reverse() - Mailing list pgsql-general

From Sam Mason
Subject Re: array_reverse()
Date
Msg-id 20091102150648.GI5407@samason.me.uk
Whole thread Raw
In response to Re: array_reverse()  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
On Mon, Nov 02, 2009 at 09:55:20AM -0500, Merlin Moncure wrote:
> On Mon, Nov 2, 2009 at 9:51 AM, Sam Mason <sam@samason.me.uk> wrote:
> > On Mon, Nov 02, 2009 at 09:20:38AM -0500, Tom Lane wrote:
> >> Craig Ringer <craig@postnewspapers.com.au> writes:
> >> > Before I go ahead and try to write a decent quality version: is there
> >> > any chance an array_reverse() function (in C) would be accepted into Pg
> >> > mainline?
> >>
> >> What would it mean for a multi-dimensional array?
> >
> > Rotating the array by 180 degrees in every dimension would give the same
> > answer for 1-dimensional arrays and give sensible answers for higher
> > dimensional arrays.

> do you think that's the typical case, or is it more common to want to
> reverse a particular slice?

I hadn't thought about that; I'm normally more concerned about making
the general case (i.e. most complicated) behave sensibly, with the
common cases being optimizations.

The problem I was solving was making 1d arrays consistent with higher
dimensional ones.  As far as I can tell, if the spec is just to rotate
by 180 degrees then the implementation is pretty easy; just run through
all the elements writing them out in reverse order.  Sizes and number of
dimensions can be completely ignored.

--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: Ivan Sergio Borgonovo
Date:
Subject: Re: pk vs unique not null differences between 8.3.4 and 8.3.8
Next
From: Sam Mason
Date:
Subject: Re: array_reverse()