NiVO / BY TECHNOGISGermany · Indonesia
Record filtering tutorial

SQLite BETWEEN: Test Inclusive Boundaries Before Filtering Drone Records

Compare BETWEEN with a half-open integer interval on constructed drone-review records, preserving endpoint membership and missing values without changing the input data.

SQLite BETWEEN: Test Inclusive Boundaries Before Filtering Drone Records

State which endpoint belongs in the report

A record can move between reports because of a boundary rule rather than a change in the underlying drone data. A reviewer asking for values between two limits may intend both endpoints to count, or may intend the upper endpoint to begin the next interval. Those policies produce different row memberships. Before interpreting an SQL selection as missing observations or an unexpected duplicate, write down the interval definition and keep it beside the query and the unchanged source records.

This tutorial uses invented integer review values in a temporary in-memory SQLite database. The numbers are not real flight times, maintenance limits, sensor readings, or NiVO product parameters. The catalogue photograph provides separate product context. The function compares an inclusive BETWEEN selection with an explicitly half-open interval and reports missing values separately. It does not edit a customer database, clean records, deduplicate assets, validate a survey, or decide which interval convention a real receiving system should use.

Read BETWEEN as two inclusive comparisons

SQLite documents x BETWEEN y AND z as equivalent to x greater than or equal to y and x less than or equal to z, except that BETWEEN evaluates the x expression once. For ordinary supplied integer values, both endpoints therefore qualify. A half-open interval instead uses greater than or equal to the lower limit and strictly less than the upper limit. These are different predicates, so a changed result does not demonstrate that SQLite lost a record or rounded a boundary.

With teaching values nine, ten, fifteen, twenty, twenty-one, and one missing value, BETWEEN ten and twenty selects ten, fifteen, and twenty. The half-open comparison selects ten and fifteen. Both leave the missing value out of their WHERE results because the comparison is not true for that row. The example returns the missing row position separately so it does not disappear from the review account. An excluded missing value must not be described as a measured value that lies outside the interval.

NiVO VTOL V5 product image showing the fixed wing and vertical-lift rotors
NiVO VTOL V5 product image showing the fixed wing and vertical-lift rotors.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 both predicates against the same bounded inputs

Run this Python function locally with a short list or tuple containing small integers or None. The function rejects Booleans, text numbers, fractions, and integers outside its stated teaching range. It also requires ordered, nonmissing integer bounds. Those restrictions keep the comparison focused on endpoint membership rather than text affinity, date parsing, or floating-point rounding. They are deliberate example limits, not SQLite limits or a recommendation for production record storage.

Each input receives its position as a row key, preserving repeated values as separate supplied observations. The function binds values through SQL parameters and returns both selection lists plus the missing positions. Results are ordered by the original position rather than relying on an unspecified database row order. The database exists only in memory and is closed after the comparison. The code does not open, write, or transform an actual delivery database, and it does not infer a physical asset identity from the numeric values.

import sqlite3

def compare_intervals(values, lower, upper):
    if not isinstance(values, (list, tuple)) or len(values) > 64:
        raise ValueError("Expected at most 64 teaching values")
    def small_int(x):
        return type(x) is int and -1000000 <= x <= 1000000
    if not small_int(lower) or not small_int(upper) or lower > upper:
        raise ValueError("Expected ordered integer bounds")
    if any(x is not None and not small_int(x) for x in values):
        raise ValueError("Expected integers or None")
    con = sqlite3.connect(":memory:")
    try:
        con.execute("CREATE TABLE sample(pos INTEGER PRIMARY KEY, value INTEGER)")
        con.executemany("INSERT INTO sample VALUES(?, ?)", enumerate(values))
        closed = con.execute(
            "SELECT pos, value FROM sample WHERE value BETWEEN ? AND ? ORDER BY pos",
            (lower, upper)).fetchall()
        half_open = con.execute(
            "SELECT pos, value FROM sample WHERE value >= ? AND value < ? ORDER BY pos",
            (lower, upper)).fetchall()
        missing = con.execute(
            "SELECT pos FROM sample WHERE value IS NULL ORDER BY pos").fetchall()
        return {"closed": closed, "half_open": half_open,
                "missing_positions": [row[0] for row in missing]}
    finally:
        con.close()

# Constructed values, not actual operational thresholds or flight records.
print(compare_intervals([9, 10, 15, 20, 21, None], 10, 20))

Test adjacent intervals and repeated boundary observations

Start with values exactly at each bound, immediately below and above them, and strictly between them. Then repeat a value at the upper endpoint. Both repeated rows should remain visible in the inclusive result, with their separate positions; neither belongs in the corresponding half-open result. Test an empty input, only missing values, and equal lower and upper bounds. Equal bounds can select matching values under BETWEEN, while the half-open interval is empty because no value can satisfy both comparisons.

For adjacent constructed intervals ten to twenty and twenty to thirty, inclusive predicates select a record at twenty in both results. Corresponding half-open intervals assign twenty to the second interval only. That is an interval-membership difference, not evidence of a duplicate observation in the input. Do not delete a record merely because two independently generated reports include it. First distinguish overlapping selection policies from repeated source observations, and retain both the query definitions and the row identities needed to explain the result.

Keep missing values and real time representations explicit

The function returns missing positions independently of both interval selections. Do not replace None with zero just to make every row fit a comparison; that would manufacture a numeric observation. Conversely, a WHERE result containing no rows does not prove the source was empty. It may reflect missing values, the chosen bounds, or the interval convention. Retain an input count and the separate missing-value finding when explaining why a report contains fewer rows than the supplied dataset.

This example intentionally avoids timestamps and floating-point measurements. Applying the same operators to a real timeline requires a declared storage representation, time reference, conversion policy, precision, and endpoint convention. A text timestamp and an integer teaching value are not interchangeable inputs. Likewise, adding a tiny numeric adjustment to force a boundary into the desired result can hide a representation problem. Establish the actual requirements and use the appropriate documented comparisons before attributing a changed row membership to a flight event or a delivery defect.

The function rejects reversed bounds instead of silently swapping them. That is a local input policy, not an additional behavior of BETWEEN. If an interface receives the limits in the wrong order, preserve the submitted values and explain the rejection before asking the operator to correct them. Automatically sorting bounds can hide an upstream field-mapping mistake. Also keep computed expressions outside the demonstration: the documentation distinguishes evaluating the left expression once from evaluating it in two separate comparisons. The fixed stored integers here isolate endpoint membership without introducing that additional evaluation question.

Deliver the query policy with the selected row identities

For an actual record handoff, retain the unchanged dataset identity, selected column and storage type, units or time reference where applicable, exact query, bound values, endpoint convention, row identity rule, SQLite and reader versions, and separate missing-value evidence. Include one independently checked boundary example. If a reporting system divides records into adjacent periods, document how its boundaries relate rather than assuming every use of the word between implies the same policy. Preserve repeated observations unless a separately authorized and justified process changes them.

In a NiVO-related data review, this method explains how one upper-endpoint record can appear in an inclusive report and disappear from a half-open report while the underlying input stays unchanged. It makes no claim about actual aircraft logs, maintenance decisions, survey quality, customer deliveries, or product database formats. The useful result is a reproducible selection rule with explicit endpoint membership and visible missing values. Continue the independent checks required by the real task before drawing an operational conclusion from the selected rows.

Technical references

  1. SQLite expressions: BETWEEN and comparison semantics ↗
  2. SQLite SELECT: WHERE excludes false and NULL results ↗
  3. Python sqlite3: in-memory databases and parameter binding ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team