helium / blockchain-etl

Blockchain follower that follows and stores the Helium blockchain
Apache License 2.0
64 stars 37 forks source link

Switch ordering of coalesced values #84

Closed abhay closed 4 years ago

abhay commented 4 years ago

The COALESCE function returns the first non-NULL argument so we were losing the new value for the old one if it wasn't NULL which is the opposite of what we wanted.

CC: @madninja

abhay commented 4 years ago

Showing that ordering matters for the PR history

etl=> select block, coalesce(block, 441087) from gateway_status where address = '11VVxHxDN8Soxo7ATugLJBfKDXdQdAhGCeRkbXBKGM4evPgvTp5';
 block  | coalesce 
--------+----------
 434982 |   434982
(1 row)
etl=> select block, coalesce(441087, block) from gateway_status where address = '11VVxHxDN8Soxo7ATugLJBfKDXdQdAhGCeRkbXBKGM4evPgvTp5';
 block  | coalesce 
--------+----------
 434982 |   441087
(1 row)
etl=> select block, coalesce(NULL, block) from gateway_status where address = '11VVxHxDN8Soxo7ATugLJBfKDXdQdAhGCeRkbXBKGM4evPgvTp5';
 block  | coalesce 
--------+----------
 434982 |   434982
(1 row)
etl=> select block, coalesce(441087, NULL) from gateway_status where address = '11VVxHxDN8Soxo7ATugLJBfKDXdQdAhGCeRkbXBKGM4evPgvTp5';
 block  | coalesce 
--------+----------
 434982 |   441087
(1 row)
etl=> select block, coalesce(NULL, NULL) from gateway_status where address = '11VVxHxDN8Soxo7ATugLJBfKDXdQdAhGCeRkbXBKGM4evPgvTp5';
 block  | coalesce 
--------+----------
 434982 | 
(1 row)