On Thu, Nov 09, 2006 at 04:37:23PM +0100, Alban Hertroys wrote:
> 'lo list,
>
> I have a plpgsql SP where I loop through a cursor. I have an internal
> variable that keeps the previous row, so that I can compare it with the
> current row in the cursor.
> Like so;
>
> DECLARE
> current table%ROWTYPE;
> previous table%ROWTYPE;
> BEGIN
> LOOP
> FETCH tableCur INTO current;
>
> -- Do stuff
>
> But, in this loop I need to compare the previous row to the current one.
> To do that I need to know whether a row was assigned to 'previous', or
> there'll be very little to compare (if it doesn't throw an error).
> How do I check for that?
>
> I guess it would be like this, but I'd like to be sure.
>
> IF previous IS NOT NULL
> THEN
> -- Compare previous and current column values
> END IF
>
> previous := current;
> END LOOP;
> END;
Try it and see. :) I think that will work.
Might be better to just capture the error.
--
Jim Nasby jim@nasby.net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)