NiVO / BY TECHNOGISGermany · Indonesia
Inventory summary tutorial

SQLite Inventory Counts: Separate Rows, Known IDs, and Distinct Drone Asset Codes

Compare three SQLite counts on a constructed drone inventory extract, expose missing identifiers, and preserve the evidence behind a summary total.

SQLite Inventory Counts: Separate Rows, Known IDs, and Distinct Drone Asset Codes

Decide what the inventory total is supposed to count

A summary headed asset count can conceal several different questions in a drone mapping or inspection handoff. It may describe rows received, rows containing an identifier, or different identifier values represented in those rows. Those quantities can disagree even when the query executes without an error. Before using a total to judge a delivery, write down which question it answers and which records it includes. A small reproducible extract is often more useful than comparing two unexplained totals from separate applications.

This tutorial uses four invented attribute records with asset identifiers A, A, B, and one SQL NULL. They are teaching inputs rather than a customer inventory, a NiVO export schema, or evidence of completed inspections. The repeated A could represent several observations or an accidental duplicate; the count alone cannot decide which interpretation is correct. The product photograph provides catalogue context only. The function creates an isolated in-memory database and never opens or changes a project file, aircraft log, or production database.

Compare three documented aggregate meanings on the same input

SQLite documents COUNT(*) as the number of rows, COUNT(X) as the number of non-NULL X values, and DISTINCT as removing duplicate inputs for a single-argument aggregate. Applied to these four records, the three expressions return four, three, and two respectively. The last result describes distinct non-null identifier values under the table comparison rules. It is not a measurement of how many physical objects were surveyed. Keep the expression beside its result so another reviewer can see the counting contract.

In the example, four rows include two occurrences of A, one occurrence of B, and one unknown identifier. Three rows therefore have a known identifier, while only A and B remain when repeated identifier values are counted once. The missing-identifier total is one, calculated as the row count minus the non-null count. Keeping that fourth diagnostic prevents an apparently tidy distinct count from hiding the incomplete record. None of these numbers explains whether the repeated A should remain or whether the unknown identifier can be recovered.

NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips
NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Run an isolated count comparison without rewriting identifiers

Run this Python function locally with the standard sqlite3 module available. It accepts a small list or tuple of text identifiers and None values, binds each value as an insertion parameter, and executes one fixed aggregate query. The table explicitly uses text affinity and BINARY collation. The returned dictionary gives every total a separate name. The connection closes even when an operation fails. The limit of sixty-four records is a teaching safeguard for this example, rather than an SQLite table-size restriction.

The printed result should report rows equal to four, non_null equal to three, distinct_non_null equal to two, and missing equal to one. Do not rename the last two fields unique assets and lost assets without additional evidence. The function deliberately leaves the original list untouched and applies no trimming, case conversion, substitution, deduplication, or repair. That makes the comparison suitable for explaining one query behavior before a project chooses its own documented identity and missing-value rules.

import sqlite3

def summarize_ids(values):
    if type(values) not in (list, tuple) or len(values) > 64:
        raise ValueError("Teaching profile: list or tuple of at most 64 records")
    if any(x is not None and type(x) is not str for x in values):
        raise ValueError("Expected text identifiers or None")
    con = sqlite3.connect(":memory:")
    try:
        con.execute("CREATE TABLE observation(asset_id TEXT COLLATE BINARY)")
        con.executemany("INSERT INTO observation VALUES(?)", [(x,) for x in values])
        row = con.execute("SELECT COUNT(*), COUNT(asset_id), "
                          "COUNT(DISTINCT asset_id) FROM observation").fetchone()
        return dict(rows=row[0], non_null=row[1],
                    distinct_non_null=row[2], missing=row[0] - row[1])
    finally:
        con.close()

# Constructed identifiers, not real inspection or delivery records.
print(summarize_ids(["A", "A", "B", None]))

Keep missing values separate from blank and unusual text

Test a NULL-only input separately from an empty input. Two None values should produce two rows, no non-null identifiers, no distinct non-null identifiers, and two missing identifiers. An empty list should return zero for every field. Those outcomes describe different received inputs even though both have zero distinct known identifiers. A report that retains only the distinct total would discard that distinction, making it harder to explain whether records were absent or present with incomplete attributes.

An empty string is text in this profile, so it participates in the non-null and distinct counts. The literal word NULL is also text rather than SQL NULL. Decide separately whether a project regards blank text, whitespace, or a reserved token as an invalid identifier. Changing those values before the query changes the question being answered. Preserve the original extract and record any authorized normalization as another operation with its own before-and-after evidence instead of allowing the count function to conceal it.

Test identity assumptions before interpreting a discrepancy

Try repeated values, different letter case, leading zeros, and whitespace around an identifier. Under this explicit text and BINARY profile, A and a remain different, as do 007 and 7, or A and a space followed by A. These test cases make the chosen comparison visible; they do not prescribe the correct identity convention for every inventory. A receiving application may use another collation or a different schema, so repeat the relevant checks against its actual documented representation before comparing totals.

Also check that reversing the constructed input order leaves all four totals unchanged, and that repeated unknown values increase missing rows without increasing the known-ID totals. Retain the query, schema, input, actual Python and SQLite versions, and output when investigating a real discrepancy. If the input was produced by a join, filter, or grouped report, inspect that upstream operation separately. A correct aggregate can summarize an unsuitable row set perfectly, so reproducing the count does not establish that the intended records reached it.

Avoid resolving a mismatch by deleting repeated rows merely to make the totals agree. Two records with the same asset identifier may carry different observation times, photographs, or review notes in a real workflow. Whether those records are redundant depends on their documented purpose and other attributes. This single-column teaching input cannot answer that question. Keep any proposed cleanup separate, retain the original records, and obtain the actual evidence needed to explain why a record should be merged, retained, or corrected.

Deliver an auditable summary with its unresolved findings

For a real handoff, label the source table or extract, selection conditions, identifier column, comparison policy, and intended counting unit. State whether the records describe assets, observations, photographs, or another entity before assigning business meaning to a number. Include the missing-value diagnostic and explain any decision about repeated identifiers. If a separate review establishes that several observations belong to one asset, record that relationship and evidence rather than treating DISTINCT as a substitute for an asset register.

In a NiVO-related inventory discussion, this approach gives another reviewer a precise explanation of why four supplied records can produce three known-ID occurrences and two distinct known-ID values. It makes no claim about mapped coverage, physical object uniqueness, inspection completion, or product performance. Preserve the received records and continue the independent identity and delivery checks required by the project. The useful outcome is a clearly labeled summary whose totals can be reproduced, with missing and repeated values still available for review.

Technical references

  1. SQLite aggregate functions: COUNT and DISTINCT semantics ↗
  2. SQLite data types and BINARY collation ↗
  3. Python sqlite3: connection, parameter binding, and returned rows ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team