Repository navigation
duckdb: resolve the rowid pseudo-column - #4697
Merged
Merged
Conversation
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
ruziba3vich
force-pushed
the
duckdb-rowid
branch
from
November 23, 2026 15:38
aad261b to
4695f5e
Compare
Fixes #4676.
Every DuckDB base table has a
rowidpseudo-column that a query can select, filter on and order by. The engine only knew the columns a table declares, so any use ofrowidfailed withunknown column "rowid".Change
convertCreateTableInfonow addsrowidto each table as a hiddenBIGINTcolumn, the same way the SQLite engine describes the hidden columns of an fts5 table. Hidden keeps it out of star expansions,INSERTtargets without a column list, and the table's model. A table that declares its own column namedrowidkeeps that column, as DuckDB does.Checked against DuckDB v2.0
DESCRIBESELECT rowid, id FROM planrowid BIGINTnullablesql.NullInt64SELECT p.rowid FROM plan p ORDER BY p.rowidrowid BIGINTnullablesql.NullInt64SELECT * FROM planSELECT rowid FROM ledger(declaresrowid VARCHAR NOT NULL)rowid VARCHARnot nullstringWHERE rowid = $1inSELECT,UPDATEandDELETE ... RETURNING *also generates.Tests
Adds the end-to-end case
duckdb_rowid. It fails onmainwith the errors from the issue and passes with this change.go test -timeout 30m ./internal/endtoendpasses locally; I did not run the database-backed--tags=examplestests.