Platform PostgreSQL 9.2
I am very new to PostgreSQL. I have this scenario, which I have been able to address in MSSQL, but the same approach does not work with Postgres.
I have this table
CREATE TABLE TEST(
ID INT,
Value1 INT,
Value2 INT
);
INSERT INTO TEST
VALUES
(1,10,0),
(2,20,0),
(3,50,0),
(4,100,0),
(5,500,0);
I need a running total in the column Value2, like so
UPDATE TEST
SET Value2 = T2.Value1-T1.Value1
FROM TEST T1
INNER JOIN TEST T2
ON T2.ID=T1.ID+1;
SELECT * FROM TEST;
While this works perfectly in MSSQL, it does not work in Postgres. The command executes successfully, but no rows get updated.
However, when I try this, I can see that the logic is correct
SELECT T2.ID,T2.Value1-T1.Value1
FROM TEST T1
INNER JOIN TEST T2
ON T2.ID=T1.ID+1;
What am I doing wrong here?