top of page

Why Can a Positive-Value Database Check Still Accept a Missing Value?

Oct 25
4 min read
Database CHECK vs Required Values: Separate required and valid; Test NULL explicitly; Review every write path.

A workshop booking requires a positive participant capacity. The team adds a database rule requiring capacity to be greater than zero and expects incomplete records to be rejected. A later import nevertheless creates a booking with no capacity recorded. The rule may be working as defined while enforcing less than the business intended.


This guide examines that specific boundary in PostgreSQL: a value can satisfy the database's CHECK mechanism without meeting a separate requirement that the value must be present. The review is useful for contributors designing import pipelines, project data models, and administrative forms.


Split the requirement into two statements


“Capacity must be a positive number” contains two potential requirements. First, a capacity must be supplied. Second, the supplied capacity must be above zero. Write them separately and ask whether each applies at every stage of the booking lifecycle.


A draft workshop might legitimately have no capacity yet. A published booking might require one. If that distinction exists, describe the states and the transition rule. Do not impose a global requirement merely because the visible form always asks for a value.


An illustrative requirement card


For a simple record that is always ready for booking, the card could say: “Capacity is required; it is an integer; its value is at least one.” For a draft-enabled workflow, the card might instead describe when the missing value becomes unacceptable.


Attach an owner and a reason to the rule. The reason may be that an availability calculation cannot proceed without a known capacity. This helps reviewers distinguish a necessary business invariant from a convenient interface default.


Understand what CHECK evaluates


PostgreSQL's constraint documentation explains that a CHECK is satisfied when its expression is true or NULL. It identifies a NOT NULL constraint as the separate mechanism for preventing a NULL column value.


For the simple always-required case, an illustrative column declaration is “capacity integer NOT NULL CHECK (capacity > 0)”. The NOT NULL requirement and the positive-value condition do different work. A specific production migration still needs review against existing records and the application's actual lifecycle.


Do not infer that every database or data tool behaves identically. Verify the behavior of the engine and version used by the project. A form validation rule and a database constraint can use similar words while having different evaluation semantics.


Test three values before adding more complexity


Start with capacity values of NULL, zero, and one. Under the simple requirement card, the first two should be rejected and the third should be accepted. Add a negative integer to confirm the lower boundary, then add a representative larger value that is within the business's permitted range.


If there is an upper limit, document and enforce it separately. A positive integer does not establish that a venue can support that number of participants. Technical validity and operational feasibility are related but distinct decisions.


Review all paths that create records


List the form, administrative editor, file import, integration, and background process that can write a booking. Use synthetic records to verify the same intended invariant through each supported route. A well-behaved form is not evidence that an import path applies the same checks.


For rejected records, review the error experience. The user or operator should know which value needs correction and whether any other part of the submission was saved. Avoid replacing a missing capacity with one merely to make the write succeed. That would turn unknown information into an invented operational fact.


Create a small evidence sheet containing the route, input, expected acceptance, observed acceptance, and returned error. Include an update that removes a previously valid capacity, not just initial creation.


Plan the change around existing data


Before tightening a live rule, inspect the records that would violate it. Separate legitimate drafts from incomplete active records and incorrectly populated records. Agree on the correction path with the data owner.


Do not bulk-fill missing values from an arbitrary average. If the true capacity is unknown, preserve that uncertainty and route the record for review. Choose a rollout approach that is compatible with the application and database change process, including any clients that still submit the old shape.


The rule is ready when the source records are understood, each writing path has an expected outcome, and the operator can recover from a rejection without guessing.


Preserve the business decision beside the schema


Keep the requirement card, boundary fixture, and lifecycle explanation with the migration or model documentation. A future contributor should be able to tell why NULL is forbidden, where incomplete drafts belong, and which tests demonstrate the behavior.


That record makes the constraint maintainable. The goal is not simply to prevent a database error; it is to ensure that stored information supports the operational decisions the team intends to make.


Continue with Can Two Valid Fields Still Make an Invalid Request? for the related planning decision.


The published FutureOS introduction describes the project as being in prelaunch. Use this guide to prepare a concrete project discussion; it does not announce an available FutureOS feature.



Prepared with AI assistance. Primary sources checked on October 25, 2026. Examples and procedures are illustrative editorial guidance, not FutureOS product announcements or an independently reviewed assessment.

Comments


bottom of page