Skip to content

duckdb: resolve the rowid pseudo-column - #4697

Merged
kyleconroy merged 1 commit into
sqlc-dev:mainfrom
ruziba3vich:duckdb-rowid
Dec 1, 2026
Merged

kyleconroy merged 1 commit into
sqlc-dev:mainfrom
ruziba3vich:duckdb-rowid

Conversation

@ruziba3vich

Copy link
Copy Markdown
Contributor

Fixes #4676.

Every DuckDB base table has a rowid pseudo-column that a query can select, filter on and order by. The engine only knew the columns a table declares, so any use of rowid failed with unknown column "rowid".

Change

convertCreateTableInfo now adds rowid to each table as a hidden BIGINT column, the same way the SQLite engine describes the hidden columns of an fts5 table. Hidden keeps it out of star expansions, INSERT targets without a column list, and the table's model. A table that declares its own column named rowid keeps that column, as DuckDB does.

Checked against DuckDB v2.0

Query DuckDB DESCRIBE sqlc with this change
SELECT rowid, id FROM plan rowid BIGINT nullable sql.NullInt64
SELECT p.rowid FROM plan p ORDER BY p.rowid rowid BIGINT nullable sql.NullInt64
SELECT * FROM plan declared columns only declared columns only
SELECT rowid FROM ledger (declares rowid VARCHAR NOT NULL) rowid VARCHAR not null string

WHERE rowid = $1 in SELECT, UPDATE and DELETE ... RETURNING * also generates.

Tests

Adds the end-to-end case duckdb_rowid. It fails on main with the errors from the issue and passes with this change. go test -timeout 30m ./internal/endtoend passes locally; I did not run the database-backed --tags=examples tests.

Every DuckDB base table has a rowid pseudo-column, a nullable BIGINT
that a query can select, filter on and order by. The engine only knew
the columns a table declares, so any use of rowid failed with
"unknown column".

Add rowid to each table as a hidden column, which keeps it out of star
expansions, INSERT targets and the table's model. A table that declares
a column named rowid keeps its own column.

Fixes sqlc-dev#4676
@kyleconroy
kyleconroy merged commit 9ac91d3 into sqlc-dev:main Dec 1, 2026
13 checks passed
kyleconroy pushed a commit that referenced this pull request Dec 1, 2026
Replaces the generated-Go golden from #4697 with an analyze case over the
same schema and queries, so the test pins what sqlc infers for rowid rather
than the code it generates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LuRZ4JY6kCxkjBm6hN7Lf3
kyleconroy added a commit that referenced this pull request Dec 1, 2026
* duckdb: resolve the rowid pseudo-column

Every DuckDB base table offers a rowid that a query can select, filter on
and order by. The converter now adds it to each table as a hidden, nullable
BIGINT column, the way the SQLite engine adds the hidden columns of an fts5
table, so it resolves by name but stays out of star expansions, INSERT
targets and the table's model. A table that declares its own rowid keeps
that column.

Fixes #4676

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LuRZ4JY6kCxkjBm6hN7Lf3

* duckdb: cover rowid with an analyze case

Replaces the generated-Go golden from #4697 with an analyze case over the
same schema and queries, so the test pins what sqlc infers for rowid rather
than the code it generates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LuRZ4JY6kCxkjBm6hN7Lf3

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

duckdb: the rowid pseudo-column is an unknown column

2 participants