Re: Need to subtract values between previous and current row

Поиск
Список
Период
Сортировка
От Marc Mamin
Тема Re: Need to subtract values between previous and current row
Дата
Msg-id CA896D7906BF224F8A6D74A1B7E54AB3198768@JENMAIL01.ad.intershop.net
обсуждение исходный текст
Ответ на Need to subtract values between previous and current row  ("Partha Guha Roy" <partha.guha.roy@gmail.com>)
Список pgsql-sql
I see 3 solutions.
 

A) self join
 
 
 
B) define a procedure that return a set of records.
   this use only a single table scan on the ordered table
 
   not tested, just the genera idea:
 
 
 
CREATE OR REPLACE FUNCTION foo()
  RETURNS SETOF <yourRecordType> AS
...
 
DELARE
previous_time int8; --(or whaever datatype you have)
rec  record ;
rec2 <yourRecordType>;
 

BEGIN
 
  FOR rec in select id, time from yourtable ORDER BY ID LOOP
 
      select into rec2 id, rec.time - previous_time;
      return next rec2;
  END LOOP;
 
END;
 
 ...
 
 
C) embedding R in Postgres
 
 

This may be a solution to implement complex cross-rows aggregation.
But I never got the time to test it;
 
I'd be interested to know  which concerns this solution can show
(stability, memory & cpu load, concurent requests....)
 
 
 
Cheers,
 
Marc
 
 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Joe
Дата:
Сообщение: Re: Need to subtract values between previous and current row
Следующее
От: Richard Broersma Jr
Дата:
Сообщение: Re: Need to subtract values between previous and current row