drizzle-team/drizzle-orm · error · DrizzleError
No fields selected for table "${tableConfig.tsName}" ("${tab
Error message
No fields selected for table "${tableConfig.tsName}" ("${tableAlias}") What it means
Thrown as a DrizzleError in buildRelationalQuery (dialect.ts:834) when the relational (db.query.*) builder ends up with zero selected fields for a table after applying the columns include/exclude rules. Because the relational API aggregates results into JSON, an empty selection would produce meaningless output, so Drizzle aborts naming the table's TS name and alias.
Source
Thrown at drizzle-orm/src/singlestore-core/dialect.ts:834
on: sql`true`,
table: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),
alias: relationTableAlias,
joinType: 'left',
lateral: true,
});
selection.push({
dbKey: selectedRelationTsKey,
tsKey: selectedRelationTsKey,
field,
relationTableTsKey: relationTableTsName,
isJson: true,
selection: builtRelation.selection,
});
}
}
if (selection.length === 0) {
throw new DrizzleError({
message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`,
});
}
let result;
where = and(joinOn, where);
if (nestedQueryRelation) {
let field = sql`JSON_TO_ARRAY(${
sql.join(
selection.map(({ field, tsKey, isJson }) =>
isJson
? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`
: is(field, SQL.Aliased)
? field.sql
: field
),View on GitHub (pinned to b7862528fd)
Solutions
- Ensure at least one column is selected: leave columns undefined (selects all) or set at least one column to true in include mode.
- If you only need relations, keep an id or minimal column set selected rather than excluding everything.
- Audit the columns config generator to guarantee a non-empty selection.
Example fix
// before
await db.query.users.findMany({ columns: { id: false, name: false, email: false } });
// after
await db.query.users.findMany({ columns: { id: true } }); Defensive patterns
Strategy: validation
Validate before calling
function hasSelectedColumn(columnsConfig) {
if (!columnsConfig) return true; // undefined selects all
const entries = Object.entries(columnsConfig);
const anyTrue = entries.some(([, v]) => v === true);
if (anyTrue) return entries.some(([, v]) => v === true);
// exclude mode: ensure at least one column remains
return entries.length < Object.keys(allColumns).length;
} Type guard
function querySelectsAtLeastOneColumn(config, tableColumns) {
if (!config.columns) return true;
const keys = Object.keys(config.columns).filter((k) => config.columns[k] !== undefined);
const include = keys.some((k) => config.columns[k] === true);
return include ? keys.some((k) => config.columns[k] === true) : keys.length < Object.keys(tableColumns).length;
} Prevention
- In relational queries, leave columns undefined (select all) or keep >=1 column selected.
- When excluding columns, never exclude every column.
- For relation-only fetches, still keep an id column selected.
When it happens
Trigger: Using the RQB-style API db.query.table.findMany({ columns: { ... } }) where every column is explicitly set to false (exclude mode) and no `with`/`extras` are requested; passing an empty columns object alongside no relations; schema misconfiguration where tableConfig.columns resolves to an empty object.
Common situations: Building a query that only wants related rows (with: {...}) but forgets to leave at least one column or use `columns: {}` semantics incorrectly; dynamically excluding all columns based on a runtime allowlist; schema where all columns were marked excluded by a generator.
Related errors
- Your "${f.path.join('->')}" field references a column "${tab
- Your "${f.path.join('->')}" field references a column "${tab
- No fields selected for table "${tableConfig.tsName}" ("${tab
- No fields selected for table "${tableConfig.tsName}" ("${tab
- Your "${f.path.join('->')}" field references a column "${tab
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/60687bf686030bf5.json.
Report an issue: GitHub.