Jaco van der Laan

Why treating SQL as a structured artifact changed everything.


SQL Is Not Text

Why treating SQL as a structured artifact changed everything.


Introduction

SQL is everywhere in data platforms.

It defines transformations, encodes business logic, and acts as the contract between data producers and consumers. Yet in most environments, SQL is treated as little more than text: copied, edited, versioned, and trusted largely by convention.

For a long time, that approach feels sufficient.

Until you need to compare, validate, migrate, or reason about SQL at scale.

During recent migration work, it became clear that many of the limitations we encountered were not caused by SQL itself — but by how we treated it.

This article explains why viewing SQL as text is a fundamental architectural constraint, and why MDDE treats SQL as a structured, semantic artifact instead.


The problem with string-based SQL

When SQL is treated as text, several things follow naturally:

  • Comparisons rely on string equality or formatting
  • Refactoring becomes manual and risky
  • Validation focuses on outputs, not intent
  • Tooling struggles to reason beyond execution

Small differences in whitespace, aliasing, or expression order can obscure deeper equivalence. Conversely, queries that look similar can behave very differently under certain conditions.

String-based handling collapses structure, semantics, and intent into a single opaque representation.

That opacity becomes costly when systems evolve.


SQL encodes intent, not just execution

At its core, SQL is a declarative language.

It expresses what is required, not how it is computed. In doing so, it encodes assumptions about:

  • Grain and aggregation
  • Filtering semantics
  • Join behavior
  • Null handling
  • Temporal interpretation

When SQL is treated as text, those assumptions remain implicit. They are understood by the author, inferred by the reader, and trusted by the system — but never made explicit or verifiable.

Parsing SQL reveals that intent.

It separates:

  • Structure from formatting
  • Semantics from syntax
  • Meaning from presentation

Once that separation exists, new possibilities open up.


Parsing changes what is possible

By parsing SQL into a structured representation, MDDE gained the ability to:

  • Normalize equivalent queries
  • Compare intent rather than text
  • Detect structural differences
  • Reason about semantics explicitly
  • Regenerate SQL deterministically

This mattered immediately during migration.

Queries that appeared different turned out to be equivalent after normalization. Others that looked similar revealed subtle semantic differences once parsed.

Instead of debating whether two queries were “the same”, we could show how they were the same — or precisely where they diverged.

That shift from interpretation to inspection changed the nature of architectural discussions.


Structure enables validation

Once SQL is structured, validation becomes more precise.

Rather than validating only results, it becomes possible to validate:

  • Whether filters are applied consistently
  • Whether aggregations align with intended grain
  • Whether joins are semantically compatible
  • Whether assumptions are explicit or inferred

This complements regression testing rather than replacing it.

Regression testing answers “do these systems behave the same?”
Structured SQL answers “why do they behave this way?”

Together, they provide a much stronger foundation for change.


Generation instead of repetition

Another consequence of treating SQL as a structured artifact is that generation becomes feasible.

When intent is captured explicitly:

  • SQL can be generated rather than copied
  • Best practices can be enforced automatically
  • Variations can be applied systematically
  • Consistency becomes scalable

In MDDE, this led to a shift away from handwritten query estates toward deterministic SQL generation based on metadata, rules, and templates.

The goal is not abstraction for its own sake, but reduction of accidental complexity.

Fewer bespoke queries mean fewer hidden assumptions.


Precision without rigidity

There is a common concern that parsing and generating SQL introduces rigidity.

In practice, the opposite was true.

By making intent explicit, teams gained more confidence to change things. When behavior is visible and comparable, change becomes safer — even when it is frequent.

Precision reduced uncertainty.
Reduced uncertainty enabled adaptability.

The constraint was never SQL.
The constraint was opacity.


SQL as architecture

When SQL is treated as text, it lives at the edges of architecture — something written after design decisions are made.

When SQL is treated as a structured artifact, it becomes architecture.

It can be:

  • Analyzed
  • Validated
  • Compared
  • Generated
  • Observed

That shift aligns SQL with the broader goals of metadata-driven data engineering: explicitness, testability, and resilience to change.


Closing

SQL has always been expressive enough to support complex data platforms.

What changed was how it was treated.

Viewing SQL as a structured, semantic artifact — rather than opaque text — removed a fundamental limitation from the architecture. It enabled better validation, clearer discussions, safer migration, and more scalable design practices.

In MDDE, this perspective is now foundational.

Not because it is theoretically elegant, but because it proved necessary in practice.


What’s next

In the next articles, I’ll build on this foundation by exploring:

  • Deterministic SQL generation
  • Executable best practices
  • Observability derived from metadata
  • Architectural Decision Records shaped by parsing and validation
  • When and where architectures should become opinionated

All with the same goal: making data architecture more explicit, testable, and resilient to change.