Re: help plpgsql, cursors, fetch into

From: Mauricio Mantilla <mauriciomantilla(at)cable(dot)net(dot)co>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: help plpgsql, cursors, fetch into
Date: 2006-04-19 21:05:24
Message-ID: 000e01c663f4$fadfaa50$988b76c8@unal40dd49d431
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes, it sure looks like a bug, this function used to work before, besides I
have another function that's pretty similar and it works.

Anyway, I did an script creating new tables and functions, and the function
worked.
I also found that in the original function i had another sentence which is
the one causing the problem...but only in the original function, in the new
function I created using the script, it doesn't cuase problems.

This is the original function:

CREATE OR REPLACE FUNCTION Asignar_test(id_solicitud integer) RETURNS
integer[] AS $$
DECLARE
curs1 refcursor;
taxi_id numeric;
punto geometry;
radio float;
asignados integer[];
tipotax varchar(1);
i integer;
BEGIN
SELECT posicion,tipo INTO punto,tipotax FROM solicitud_test WHERE
id_solicitud=id;
radio :=0.002;
WHILE (SELECT id FROM taxi_test WHERE posicion && Expand(punto,0.1) AND
Distance(punto,posicion) < radio AND tipo_taxi like tipotax AND estado =
'l' LIMIT 1) is null AND radio < 1 LOOP
radio := radio + 0.002;
END LOOP;
curs1 := cercanos_test(punto, radio, tipotax);
i:=0;
LOOP
FETCH curs1 INTO taxi_id;
EXIT WHEN NOT FOUND;
i:=i+1;
asignados[i] := taxi_id;
UPDATE taxi SET estado = 'p' where id = taxi_id;
END LOOP;
CLOSE curs1;
RETURN asignados;
END;
$$ LANGUAGE 'plpgsql';

The function works again when I delete the UPDATE sentence.

----- Original Message -----
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mauricio Mantilla" <mauriciomantilla(at)cable(dot)net(dot)co>
Cc: <pgsql-general(at)postgresql(dot)org>
Sent: Wednesday, April 19, 2006 11:26 AM
Subject: Re: [GENERAL] help plpgsql, cursors, fetch into

> Mauricio Mantilla <mauriciomantilla(at)cable(dot)net(dot)co> writes:
>> Hi, I'm having a problem with FETCH INTO, but I can't figure out what it
>> is.
>
> That kinda looks like a bug. Which PG version are you using exactly?
> Could you provide a self-contained test case (ie, a script to create
> the needed tables and sample data)?
>
> regards, tom lane
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.385 / Virus Database: 268.4.4/318 - Release Date: 18/04/2006
>
>

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.4.4/318 - Release Date: 18/04/2006

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Clodoaldo Pinto 2006-04-19 21:29:32 Calling the same function more than once with the same arguments
Previous Message John F Rizzo 2006-04-19 19:52:11 plperl on AIX