recursive sql - Mailing list pgsql-sql

From ml@ft-c.de
Subject recursive sql
Date
Msg-id eaf4082e-79ac-7a5d-bcf8-63ce66087365@ft-c.de
Whole thread Raw
Responses AW: recursive sql  (Stöcker, Martin <Martin.Stoecker@etl-datenservice.de>)
Re: recursive sql  (Igor Andriychuk <2.andriychuk@gmail.com>)
List pgsql-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: Mike Martin
Date:
Subject: Error - Arrays must contain only scalars and other arrays when array element is an array
Next
From: Stöcker, Martin
Date:
Subject: AW: recursive sql