Group by with showing full rows in Postgresql
You just want this

SELECT a,b,sum(b)
FROM foo
GROUP BY a,b;

 a | b | sum 
---+---+-----
 1 | 2 |   4
 1 | 1 |   2


If you don't want to reduce the row set, you can do this..

SELECT a,b,sum(b) OVER (PARTITION BY a,b)
FROM foo;

 a | b | sum 
---+---+-----
 1 | 1 |   2
 1 | 1 |   2
 1 | 2 |   4
 1 | 2 |   4