From: | Ragnar Hafstað <gnari(at)simnet(dot)is> |
---|---|
To: | "GIROIRE Nicolas (COFRAMI)" <nicolas(dot)giroire(at)airbus(dot)com> |
Cc: | "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: sort array optimisation in pl/perl |
Date: | 2005-03-24 20:53:06 |
Message-ID: | 1111697586.1995.17.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2005-03-24 at 15:49 +0100, GIROIRE Nicolas (COFRAMI) wrote:
> I create an array which is result of query on postgresql database and
> then I want to sort rows in a particular way (impossible by query on
> database).
can you give us more details on this particular sort order?
> My solution consists to put a rows (indice m+1) in a temporary other
> and then move all element before indice n to m in rows with indice n+1
> to m+1 and last i put my temporary variable to indice n.
> I want to know if somebody know a better solution.
>
> I think of 2 solutions but i don't success to apply :
> - the first is to use list in which I could deplace references as a
> chained list
> - the second will be to deplace tab[n..m] to tab[n+1..m+1] in one
> instruction as ada language
it all depends on the expected sizes of your arrays, but perl has
some nice array operations, such as slices and splice()
these come to mind:
$x=$arr[$m+1];@arr[$n+1(dot)(dot)$m+1]=(at)arr[$n(dot)(dot)$m];$arr[$n]=$x;
or:
@arr[$n..$m+1]=($arr[$m+1],@arr[$n..$m]);
gnari
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Stark | 2005-03-24 21:15:05 | Re: plperl doesn't release memory |
Previous Message | Tom Lane | 2005-03-24 20:52:55 | Re: plperl doesn't release memory |