PostgreSQL 9.3
tilbyder som pæne JSON-funktioner, som kan bruges til sådanne opgaver uden at definere nye funktioner eller kende et antal kolonner.
SELECT id, (k).key as year, (k).value as value FROM
(SELECT j->>'id' as id, json_each_text(j) as k
FROM (
SELECT row_to_json(tbl) as j FROM tbl)
as q)
as r
WHERE (k).key <> 'id';
http://sqlfiddle.com/#!15/1714b/13