Jaco van der Laan

Deterministic SQL Generation

07/02/2026  ·  Data Engineering  ·  Reproducibility  ·  SQL Code Generation

metadata sql
‹ ›

Why generating SQL from intent proved safer than maintaining it by hand.


Deterministic SQL Generation

Why generating SQL from intent proved safer than maintaining it by hand.


Introduction

Once SQL is treated as a structured artifact rather than text, a new question inevitably arises:

If intent can be parsed, analyzed, and validated — why is SQL still written manually?

For a long time, hand-written SQL feels like the most direct and flexible option. It gives engineers control, expressiveness, and speed. In small systems, that trade-off is often reasonable.

At scale, and under change, it becomes fragile.

During recent work, MDDE crossed a threshold where generating SQL deterministically from metadata was no longer an experiment — it became the safer option.

This article explains why.


Handwritten SQL does not age well

Most SQL estates grow organically.

Queries are copied, adapted, extended, and tuned over time. Even with good intentions, this leads to:

  • Diverging patterns for similar logic
  • Inconsistent naming and structure
  • Subtle semantic drift
  • Hidden assumptions embedded in query text

None of this is immediately visible.

The cost only appears when change is required:

  • Migration to a new platform
  • Reinterpretation of business logic
  • Systematic validation
  • Enforcement of new standards

At that point, the flexibility of handwritten SQL turns into unpredictability.


Determinism is not about control — it’s about repeatability

The word deterministic often raises concerns:

  • Loss of flexibility
  • Over-standardization
  • Reduced expressiveness

In practice, determinism addresses a different problem.

It answers questions like:

  • Can this query be reproduced exactly?
  • Can equivalent intent be rendered consistently?
  • Can differences be explained structurally rather than textually?
  • Can change be applied systematically instead of manually?

Deterministic generation doesn’t remove flexibility.
It removes accidental variation.


From intent to SQL

In MDDE, deterministic SQL generation became possible once three things were in place:

  1. Explicit intent
    Business logic, structure, and assumptions captured as metadata.
  2. Parsed structure
    SQL represented as a model, not a string.
  3. Validation feedback
    Regression and structural checks informing correctness.

With these in place, SQL generation became a rendering step — not a creative one.

The system already knew:

  • What needed to be selected
  • How it should be aggregated
  • Which filters applied
  • How joins were interpreted

Generating SQL was simply making that intent executable.


Generation reduces risk under change

One of the most important benefits of deterministic generation emerged during change.

When logic is generated:

  • Refactoring happens at the intent level
  • Platform differences can be handled centrally
  • Best practices are applied consistently
  • Structural changes propagate predictably

Instead of touching hundreds of queries, change is applied once — and rendered many times.

This does not eliminate the need for validation.
But it makes validation far more meaningful.

Differences are no longer accidental.
They are deliberate, explainable, and traceable.


Best practices become enforceable by design

Handwritten SQL relies on discipline.

Generated SQL relies on design.

When SQL is generated:

  • Naming conventions are guaranteed
  • Join patterns are consistent
  • Filter placement is predictable
  • Anti-patterns can be prevented entirely

This shifts best practices from guidance to enforcement.

Not through reviews or documentation, but through construction.

The architecture stops asking engineers to do the right thing —
it makes the right thing the default outcome.


Precision enables confidence

One recurring theme across the MDDE work is the relationship between precision and confidence.

When SQL is deterministic:

  • Engineers trust regeneration
  • Review focuses on intent, not syntax
  • Comparisons become structural
  • Validation results are easier to interpret

Confidence no longer depends on familiarity with individual queries.
It depends on trust in the system that produces them.

That trust is earned through transparency, validation, and repeatability.


Determinism does not eliminate expertise

Deterministic generation is sometimes misunderstood as removing engineering judgment.

In reality, it moves judgment to a higher level:

  • Modeling intent
  • Defining rules
  • Deciding where flexibility is allowed
  • Making architectural trade-offs explicit

Expertise is still required — it is simply applied where it has the most leverage.


SQL as a reproducible artifact

Once SQL is generated deterministically, it becomes something different.

It is no longer:

  • A fragile hand-crafted object
  • A unique expression tied to its author

It becomes:

  • A reproducible artifact
  • A verifiable outcome
  • A transparent projection of intent

That shift aligns SQL with the broader architectural goals of MDDE: explicitness, testability, and resilience to change.


Closing

Deterministic SQL generation was not introduced for elegance or abstraction.

It emerged as a practical response to scale, change, and validation.

When intent is explicit and behavior is observable, generation becomes the safest way to ensure consistency — not the most restrictive one.

In MDDE, deterministic SQL generation is now a foundation.

Not because it replaces engineering skill, but because it allows that skill to be applied where it matters most.


What’s next

In the next articles, I’ll explore:

  • Executable best practices as architectural rules
  • Observability derived directly from metadata
  • Architectural Decision Records shaped by generation and validation
  • When flexibility becomes ambiguity
  • How opinionated architecture reduces long-term friction

All continuing the same theme: making data architecture explicit, testable, and durable under change.