Dada uma tabela como:
label | x | y | z
-------+-------+-------+------
AAA | NULL | 7 | 9
BBB | 0 | 10 | 0
CCC | 12 | NULL | 0
create table coords (label text, x integer, y integer, z integer);
insert into coords(label,x,y,z)
values
('AAA',NULL,7,9),
('BBB',0,10,0),
('CCC',12,NULL,0);
Preciso inserir em outra tabela valores label
quando não forem NULL ou 0s. Assim o resultado final será:
label | coord | value |
------+-------+-------+
AAA | y | 7 |
AAA | z | 9 |
BBB | y | 10 |
CCC | x | 12 |
Eu tentei com diferente OVER/PARTITION
, mas provavelmente está faltando alguma coisa. Qualquer ajuda?
Isso é realmente direto:
ou usando
LATERAL
: