Re: ROWTYPE initialization question

Поиск
Список
Период
Сортировка
Искать
От
Jim C. Nasby
Тема
Re: ROWTYPE initialization question
Дата
Msg-id
20061114193717.GN90133@nasby.net
Ответ на
Список
Дерево обсуждения
ROWTYPE initialization question Alban Hertroys <alban@magproductions.nl>
Re: ROWTYPE initialization question "Jim C. Nasby" <jim@nasby.net>
Re: ROWTYPE initialization question Alban Hertroys <alban@magproductions.nl>
Re: ROWTYPE initialization question Jim Nasby <jim@nasby.net>
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)
В списке pgsql-general по дате отправления
От: Dave Page
Дата:
От: Jim C. Nasby
Дата:
Сообщение: Re: SQL Join for a Calculation
FAQ