Re: Convert Cursor to array

From: "GIROIRE Nicolas (COFRAMI)" <nicolas(dot)giroire(at)airbus(dot)com>
To: 'Richard Huxton' <dev(at)archonet(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Convert Cursor to array
Date: 2005-03-11 14:12:01
Message-ID: 1904E3EB39448246A7ECB76DF34A70B0036A3FAA@TOCOMEXC03
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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(at)archonet(dot)com]
Envoyé : vendredi 11 mars 2005 15:01
À : GIROIRE Nicolas (COFRAMI)
Cc : 'pgsql-general(at)postgresql(dot)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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2005-03-11 14:23:51 Re: Problem with inherited table, can you help?...
Previous Message Thomas Hallgren 2005-03-11 14:11:07 Re: PostgreSQL still for Linux only?