AW: recursive sql - Mailing list pgsql-sql

From Stöcker, Martin
Subject AW: recursive sql
Date
Msg-id f890658548ac4f8cb7e6cef6d9179605@etl-datenservice.de
Whole thread Raw
In response to recursive sql  (ml@ft-c.de)
List pgsql-sql

Hi Franz


I think you don't need to use recursivy but window function will do.


Mit freundlichen Grüßen

Martin Stöcker 
-----------------------------------------
ETL Datenservice GmbH
Widdersdorfer Str. 415 | D-50933 Köln
Telefon: +49(0)2219544010
Fax: +49
(0)2219544015
Email: Martin.Stoecker@etl-datenservice.de

ETL Datenservice GmbH
Widdersdorfer Str. 415 · 50933 Köln
Geschäftsführer: Dr. Dirk Goldner, ppa Melanie Lillich
Amtsgericht Köln · HRB 75439 · USt.-Id: DE 122 805 685
www.etl-datenservice.de
Email: info@etl-datenservice.de

Die STB Datenservice ist jetzt ETL Datenservice.
Sie erreichen uns nun unter dem Zusatz @etl-datenservice.de

Von: ml@ft-c.de <ml@ft-c.de>
Gesendet: Sonntag, 9. August 2020 08:28:44
An: pgsql-sql@lists.postgresql.org
Betreff: recursive sql
 
Hello,

the table
create table tt (
   ts timestamp,
   c numeric) ;

insert into tt values
  ('2019-12-31',1), ('2020-01-01',2),
  ('2020-07-02',3), ('2020-07-06',4),
  ('2020-07-07',5), ('2020-07-08',6);

My question: It is possible to get an
   additional column (named c2)
   with
   ( c from current row ) + ( c2 from the previous row ) as c2

the result:
ts  c c2
..  1  1 -- or null in the first row
..  2  3
..  3  6
..  4 10
...

with recursive ema as ()
select ts, c,
   -- many many computed_rows
   -- <code> as c2
from tt  -- <- I need tt on this place


thank you for help
Franz


pgsql-sql by date:

Previous
From: ml@ft-c.de
Date:
Subject: recursive sql
Next
From: ml@ft-c.de
Date:
Subject: Re: recursive sql