How to pivot a table skipping bad value in Postgres
This is really straight forward:

INSERT INTO new_table 
    (label, coord, value)
SELECT label, 'x', x  FROM coords  WHERE x &lt;&gt; 0 
UNION ALL
SELECT label, 'y', y  FROM coords  WHERE y &lt;&gt; 0 
UNION ALL
SELECT label, 'z', z  FROM coords  WHERE z &lt;&gt; 0 ;


or using LATERAL:

INSERT INTO new_table 
    (label, coord, value)
SELECT c.label, v.coord, v.value  
FROM coords AS c
    , LATERAL 
     ( VALUES ('x', x),
              ('y', y),
              ('z', z)
     ) AS v (coord, value)
WHERE v.value &lt;&gt; 0 ;