Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k4epH-0003ox-26 for pgsql-sql@arkaria.postgresql.org; Sun, 09 Aug 2020 06:28:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k4epE-0000fl-M7 for pgsql-sql@arkaria.postgresql.org; Sun, 09 Aug 2020 06:28:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k4epE-0000fe-Dy for pgsql-sql@lists.postgresql.org; Sun, 09 Aug 2020 06:28:56 +0000 Received: from einhorn-mail.in-berlin.de ([217.197.80.20]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k4ep7-0008Qh-6a for pgsql-sql@lists.postgresql.org; Sun, 09 Aug 2020 06:28:55 +0000 X-Envelope-From: ml@ft-c.de X-Envelope-To: Received: from authenticated.user (localhost [127.0.0.1]) by einhorn.in-berlin.de with ESMTPSA id 0796SiQc010309 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Sun, 9 Aug 2020 08:28:44 +0200 Reply-To: ml@ft-c.de To: pgsql-sql@lists.postgresql.org From: ml@ft-c.de Subject: recursive sql Message-ID: Date: Sun, 9 Aug 2020 08:28:44 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 -- as c2 from tt -- <- I need tt on this place thank you for help Franz