{"id":"b111b9de74348f1c","repo":"drizzle-team/drizzle-orm","slug":"no-fields-selected-for-table-tableconfig-tsname-b111b9","errorCode":null,"errorMessage":"No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\"). You need to have at least one item in \"columns\", \"with\" or \"extras\". If you need to select all columns, omit the \"columns\" key or set it to undefined.","messagePattern":"No fields selected for table \"(.+?)\" \\(\"(.+?)\"\\)\\. You need to have at least one item in \"columns\", \"with\" or \"extras\"\\. If you need to select all columns, omit the \"columns\" key or set it to undefined\\.","errorType":"exception","errorClass":"DrizzleError","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/mysql-core/dialect.ts","lineNumber":1225,"sourceCode":"\t\t\t\t);\n\t\t\t\tlet fieldSql = sql`(${builtRelation.sql})`;\n\t\t\t\tif (is(relation, Many)) {\n\t\t\t\t\tfieldSql = sql`coalesce(${fieldSql}, json_array())`;\n\t\t\t\t}\n\t\t\t\tconst field = fieldSql.as(selectedRelationTsKey);\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:\n\t\t\t\t\t`No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\"). You need to have at least one item in \"columns\", \"with\" or \"extras\". If you need to select all columns, omit the \"columns\" key or set it to undefined.`,\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_array(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field }) =>\n\t\t\t\t\t\tis(field, MySqlColumn)\n\t\t\t\t\t\t\t? sql.identifier(this.casing.getColumnCasing(field))\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","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/mysql-core/dialect.ts#L1207-L1243","documentation":"Thrown by MySqlDialect.buildRelationalQueryWithoutLateralSubqueries (line 1225, non-lateral variant) when the computed selection is empty. Same condition as the lateral variant but for runtimes/configs that use the non-lateral relational query builder. The message is more explicit, listing columns/with/extras as the sources to populate.","triggerScenarios":"db.query.X.findMany/findFirst with a columns object that excludes everything (all false) and no `with`/`extras`, executed on a path that uses the non-lateral relational builder.","commonSituations":"All-false columns object built dynamically; excluding all columns accidentally while intending to fetch only relations; refactor that emptied the selected columns.","solutions":["Ensure at least one source of fields: set a column to true, add a `with` relation, or add an `extras` entry.","Omit the columns key entirely (or set to undefined) to select all table columns.","Validate dynamic column configs to guarantee at least one inclusion before querying."],"exampleFix":"// before\ndb.query.posts.findMany({\n  columns: { id: false, title: false, body: false },\n});\n\n// after - include at least one or omit\ndb.query.posts.findMany({ columns: { id: true } });\n// or\n db.query.posts.findMany({});","handlingStrategy":"validation","validationCode":"function validateRqbConfig(cfg: { columns?: Record<string, boolean>; with?: object; extras?: object }) {\n  if (cfg.columns && Object.values(cfg.columns).every((v) => v === false)) {\n    if (!cfg.with && !cfg.extras) throw new Error('RQB config selects nothing; add a column/with/extras');\n  }\n}","typeGuard":"function rqbHasFields(cfg: { columns?: Record<string, boolean>; with?: object; extras?: object }): boolean {\n  if (!cfg.columns) return true;\n  const v = Object.values(cfg.columns);\n  return v.includes(true) || (v.some((x) => x === false) && !v.every((x) => x === false)) || Boolean(cfg.with) || Boolean(cfg.extras);\n}","tryCatchPattern":null,"preventionTips":["Ensure at least one column/with/extras is selected in RQB configs.","Set columns to undefined to select all.","Validate dynamically built columns objects."],"tags":["mysql","rqb","relational","select","config"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}