liveBook · Manning

Select * exclude

As explained in DuckDB in Action

SELECT * EXCLUDE is a DuckDB SQL projection syntax that selects all columns except those named in the exclusion list.

SELECT * EXCLUDE is DuckDB’s projection syntax for returning every column except the named exclusions. It solves a common data-preparation problem: keeping nearly all fields without manually listing a long, fragile column list. section 1.2 section 3.5.1

Use it when a relation contains many useful columns and only a few irrelevant ones. The query stays readable while avoiding columns you do not need, although ordinary SELECT * can become unstable as table definitions change and may access more data than necessary. section 3.5.1

Keep prices, drop the identifier

A prices relation contains id, value, valid_from, and valid_until. Return the three business fields without enumerating them: SELECT * EXCLUDE (id) FROM prices;. You can name multiple columns in the exclusion list. section 3.5.1

SELECT * EXCLUDE (id)
FROM prices;

Run the compact projection directly against the prices relation and inspect the resulting columns. section 3.5.1

Useful variations and nearby DuckDB projection features include:

  • Use SELECT * REPLACE to retain all columns while substituting a transformed expression, such as a rounded kWh value. section 3.5.1
  • Use COLUMNS with a pattern or expression when columns should be selected by name, such as fields beginning with valid. section 3.5.1

How DuckDB in Action covers it

How deep it goes
Defines exclusion syntax and trade-offs, then demonstrates a prices query; it stops short of implementation internals.
Examples
Uses a prices relation, excludes id, and contrasts the syntax with explicit column enumeration.
What it assumes
Assumes basic SQL projection and relations while teaching the exclusion pattern through a concrete table example.
What you can do after
Apply it via DuckDB SQL to project nearly all relation columns while omitting named fields.
How it connects
Connects SELECT * EXCLUDE with SELECT *, SELECT * REPLACE, COLUMNS, and data pipelines.

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.