> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL row metadata

> Select row IDs and row addresses, with statement-wide visibility and storage limitations.

Enterprise only

Lance provides `_rowid` and `_rowaddr` as row metadata rather than stored data
columns. Both SQL fields have type [`UInt64`](https://docs.lancedb.com/oss/v0-42-0/sql/data-types).
[Select](https://docs.lancedb.com/oss/v0-42-0/sql/dql/select.md) either column explicitly:

```sql SQL icon="database" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
SELECT _rowid, id FROM items;
SELECT id, _rowaddr FROM items;
SELECT id FROM items WHERE _rowid = 42;
```

Output columns follow the order of the projection. `_rowoffset` and `__row_id`
are unsupported SQL spellings.

## Wildcards apply across the statement

A statement that does not reference row metadata keeps its ordinary `SELECT *`
schema. Referencing `_rowid` or `_rowaddr` anywhere in a statement makes that
column visible to wildcards throughout the same statement, including nested
queries and joins:

```sql SQL icon="database" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
-- Includes the stored columns and _rowid, because the filter references it.
SELECT * FROM items WHERE _rowid >= 0;

-- The inner wildcard also includes _rowid.
SELECT * FROM (SELECT * FROM items) AS s WHERE s._rowid >= 0;

-- Excluding _rowid leaves only the stored columns.
SELECT * EXCLUDE (_rowid) FROM items;
```

Referencing `_rowid` alone does not expose `_rowaddr`, or vice versa. A later
statement starts with the ordinary schema again.

Statements that reference row metadata cannot use `NATURAL JOIN`, including
references in wildcard modifiers or `USING` keys. Otherwise, the exposed
metadata columns would become implicit join keys and could change which rows
match. Use `JOIN ON` or `JOIN USING` with explicit keys instead.

## Row identity and writes

`_rowaddr` identifies a physical row location and can change during compaction.
`_rowid` remains stable across compaction only on tables created with stable row
IDs enabled. Tables created through SQL default to stable row IDs disabled;
on those tables, `_rowid` equals `_rowaddr` and can also change during compaction.

Materialized views that read `_rowid` or `_rowaddr` rebuild fully on every refresh,
including views that read `_rowid` from tables with stable row IDs enabled.

Row metadata names cannot be written as data columns. INSERT, CREATE TABLE AS,
and materialized-view definitions reject reserved output names. Use an ordinary
alias when storing a metadata value:

```sql SQL icon="database" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
CREATE TABLE copied AS SELECT _rowid AS source_row_id, id FROM items;
```

The copied value is ordinary data; it does not acquire row identity semantics.

## WAL tables and scan capacity

SQL projections and filters using `_rowid` or `_rowaddr` are rejected on
WAL-backed tables. Rows in the fresh tier have no row identity equivalent.

Metadata range predicates, such as `_rowid > 0`, can scan on the query node
instead of using executors. Account for query-node capacity for large range
queries. Direct row-ID lookups, such as `_rowid = 42`, are available when the
desired IDs are known.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.