글

라벨이 Data Quality인 게시물 표시

PostgreSQL COUNT(*) and COUNT(column) Give Different Totals for NULLs

Compute all three counts from the same filtered input. COUNT(*) counts rows. COUNT(device_id) counts rows with a non-NULL ID. COUNT(DISTINCT device_id) counts the distinct non-NULL IDs. Reconcile a four-row fixture Take a synthetic input of A, A, B, NULL for device IDs. Those values yield 4 events, 3 events with IDs and 2 identified devices. A missing identifier does not erase the underlying event. Two rows for A represent two observations of the same identified device. Measure missing values explicitly SELECT COUNT(*) AS events, COUNT(device_id) AS with_id, COUNT(DISTINCT device_id) AS devices, COUNT(*) - COUNT(device_id) AS missing_id FROM daily_events; Also inspect the source contract for blank strings. PostgreSQL treats an empty text string as a value, so it can enter both populated and distinct counts. Normalizing blank strings requires a deliberate rule and a test for whitespace-only input. Use the denominator named in the report If the metric is i...