Mapping SQLite result columns back to their source `table.column`

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Developers running arbitrary SQLite queries can now programmatically trace every result column back to its originating table.column, enabling tools like Datasette to auto-annotate query output with provenance metadata.

Read this as

Simon Willison explored how to find out which original table and column each piece of a SQLite database query result came from, even for complicated queries with joins and CTEs (temporary named query blocks). He used Claude Code, an AI coding tool, to test approaches. It matters to anyone building tools that show database query results with extra context. No dates or performance figures are given.

Willison's team at Datasette wants arbitrary SQL queries to display provenance information showing which source tables produced each result column. Claude Code (Opus 4.8) delivered three working approaches: the third-party apsw library's description_full, a ctypes bridge to the sqlite3_column_table_name() C function, and parsing EXPLAIN output. Costs are engineering time only; adoption is confined to projects needing SQLite column metadata.

SQLite exposes result-column provenance via its column-metadata API, but only when compiled with SQLITE_ENABLE_COLUMN_METADATA, and Python's built-in sqlite3 module never surfaces it. Claude Code (Opus 4.8) found three viable routes: apsw's cursor.description_full for direct access; a pure-stdlib ctypes bridge (column_provenance.py) calling sqlite3_column_table_name(); and interrogating EXPLAIN output. The goal is Datasette support for queries like joined users/orders selects, including CTEs.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

SQLite Datasette apsw Claude Code Python

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading