{"id":"60687bf686030bf5","repo":"drizzle-team/drizzle-orm","slug":"no-fields-selected-for-table-tableconfig-tsname-60687b","errorCode":null,"errorMessage":"No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")","messagePattern":"No fields selected for table \"(.+?)\" \\(\"(.+?)\"\\)","errorType":"validation","errorClass":"DrizzleError","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/singlestore-core/dialect.ts","lineNumber":834,"sourceCode":"\t\t\t\t\ton: sql`true`,\n\t\t\t\t\ttable: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),\n\t\t\t\t\talias: relationTableAlias,\n\t\t\t\t\tjoinType: 'left',\n\t\t\t\t\tlateral: true,\n\t\t\t\t});\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage: `No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")`,\n\t\t\t});\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`JSON_TO_ARRAY(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field, tsKey, isJson }) =>\n\t\t\t\t\t\tisJson\n\t\t\t\t\t\t\t? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),","sourceCodeStart":816,"sourceCodeEnd":852,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/singlestore-core/dialect.ts#L816-L852","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait db.query.users.findMany({ columns: { id: false, name: false, email: false } });\n// after\nawait db.query.users.findMany({ columns: { id: true } });","handlingStrategy":"validation","validationCode":"function hasSelectedColumn(columnsConfig) {\n  if (!columnsConfig) return true; // undefined selects all\n  const entries = Object.entries(columnsConfig);\n  const anyTrue = entries.some(([, v]) => v === true);\n  if (anyTrue) return entries.some(([, v]) => v === true);\n  // exclude mode: ensure at least one column remains\n  return entries.length < Object.keys(allColumns).length;\n}","typeGuard":"function querySelectsAtLeastOneColumn(config, tableColumns) {\n  if (!config.columns) return true;\n  const keys = Object.keys(config.columns).filter((k) => config.columns[k] !== undefined);\n  const include = keys.some((k) => config.columns[k] === true);\n  return include ? keys.some((k) => config.columns[k] === true) : keys.length < Object.keys(tableColumns).length;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["relational-query","select","singlestore","schema","rqb"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}