How to return values from "upsert" query in case when UPDATE has been performed?
You need to use a second CTE for the INSERT:

WITH upsert AS (
  UPDATE tbl SET a = 2 
  WHERE a = 1 
  RETURNING tbl.*
), inserted AS (
  INSERT INTO tbl (a)
  SELECT 1 WHERE NOT EXISTS( SELECT * FROM upsert )
  RETURNING *
)
select *
from upsert
union all
select * 
from inserted