liveBook · Manning

Schema

As explained in DuckDB in Action

A schema is a formal description of data fields, types, and structural organization.

A schema is a formal description of data fields, types, and structural organization. In a relational database, tables contain named columns with defined data types, while schemas organize those tables within a database. A useful schema makes data addressable, joinable, and analyzable without forcing every query to rediscover its structure. section 3.2.2

Schema design is a practical trade-off rather than a one-time specification. A normalized energy dataset separates systems, readings, and prices; keys may be externally generated, sequence-based, or composed from meaningful fields. When requirements change, ALTER TABLE can add, drop, or rename columns and tables, while unsupported constraint changes require recreating the table. section 3.2.2 section 3.3.2

A schema can be inspected or inferred at several layers:

  • Inspect relational columns, types, nullability, keys, defaults, and extra metadata with DESCRIBE. section 5.5
  • Infer structure from nested JSON, where arrays may contain STRUCT values and inconsistent files may require explicit unnesting, casting, or flattening. section 5.3
  • Inspect Parquet’s logical and physical schema separately, including types such as DATE, INT32, INT64, and BYTE_ARRAY. section 5.5
  • Combine Parquet files with differing schemas by name when needed; missing or differently named columns become NULL. section 10.4.3

Inspect and evolve a schema

Use DuckDB to inspect a file before querying it, then extend a relational table when a new requirement appears: DESCRIBE FROM 'atp/atp_rankings.parquet'; ALTER TABLE prices ADD COLUMN IF NOT EXISTS valid_until DATE; DESCRIBE reveals fields such as ranking_date, rank, points, and player_id with their inferred types. ALTER TABLE adds price validity without rebuilding the table; changing constraints may still require table recreation. section 5.5 section 3.3.2

Figure 3.1 Energy consumption schema
figure

Use the energy-consumption schema diagram to trace how systems, readings, and prices are separated and related. section 3.2.2

How DuckDB in Action covers it

How deep it goes
Defines tables, types, keys, nested structures, and Parquet metadata, then stops short of exhaustive constraint management.
Examples
Uses energy tables, nested football-shot JSON, ATP rankings Parquet, DESCRIBE, ALTER TABLE, unnest, casting, and schema diagrams.
What it assumes
Assumes basic DuckDB and SQL access while defining relational terms and demonstrating schema inspection from zero.
What you can do after
Operate/configure DuckDB to inspect inferred schemas, evolve tables, flatten nested data, and query Parquet metadata.
How it connects
Connects relational databases, tables, data types, primary keys, surrogate keys, JSON, Parquet, views, and SQL.

Also explained in

Compare how 44 books explain schema →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.