my sort algorithm is a very particular solution.
In fact, I put record in array to allow me to sort record. I sort them by using one column of my table but the column indx can have duplicate value and it's volontary.
here is the order algorithm :
for i in 1..recordcount loop
tmp_row := children[i];
indx := tmp_row[5];
if (indx<i) then
-- on déplace les éléments pour laisser la place à l'élément qu'on déplace
for j in 0..(i-indx-1) loop
children[i-j] := children[i-j-1];
end loop;
-- on met l'élément à sa nouvelle position
children[indx] := tmp_row;
end if;
end loop;
It's particular to my system. I won't go to explain my choice but if someone has an idea to save time.
-----Message d'origine-----
De : Richard Huxton [mailto:dev@archonet.com]
Envoyé : vendredi 11 mars 2005 15:01
À : GIROIRE Nicolas (COFRAMI)
Cc : 'pgsql-general@postgresql.org'
Objet : Re: [GENERAL] Convert Cursor to array
GIROIRE Nicolas (COFRAMI) wrote:
> Hi,
>
> In a procedure, I put data of Cursor in a two-dimensional array. This allows
> me to sort rows.
>
> The problem is this method is too slow.
>
> In fact, I translate a pl/sql procedure to a plpgsql.
> Under Oracle, we use bulk and I search to use equivalent of this under
> postgresql.
>
> Is that exist ?
No, but there might be other ways to do this. Can you explain why you
need to sort within the function rather than using "order by"?
If you're sure you want to sort within the function, take a look at one
of the alternative procedural languages. PL/pgsql evaluates all
expressions by passing them to the SQL parser, which keeps things simple
and consistent but isn't efficient if you want to do a lot of data
processing.
--
Richard Huxton
Archonet Ltd
This mail has originated outside your organization,
either from an external partner or the Global Internet.
Keep this in mind if you answer this message.