{"record":{"id":"ffa3d1c1821a25e4","repo":"actualbudget/actual","slug":"invalid-field-name-are-you-trying-to-select","errorCode":null,"errorMessage":"Invalid field \"${name}\", are you trying to select a function? You need to name the expression","messagePattern":"Invalid field \"(.+?)\", are you trying to select a function\\? You need to name the expression","errorType":"exception","errorClass":"CompileError","httpStatus":null,"severity":"error","filePath":"packages/loot-core/src/server/aql/compiler.ts","lineNumber":918,"sourceCode":"\n          return fields\n            .map(field => {\n              const compiled = compileExpr(state, '$' + field);\n              state.outputTypes.set(field, compiled.type);\n              return compiled.value + ' AS ' + quoteAlias(field);\n            })\n            .join(', ');\n        }\n\n        const compiled = compileExpr(state, '$' + expr);\n        state.outputTypes.set(expr, compiled.type);\n        return compiled.value + ' AS ' + quoteAlias(expr);\n      }\n\n      const [name, value] = Object.entries(expr)[0];\n      if (name[0] === '$') {\n        state.compileStack.push({ type: 'value', value: expr });\n        throw new CompileError(\n          `Invalid field \"${name}\", are you trying to select a function? You need to name the expression`,\n        );\n      }\n\n      if (typeof value === 'string') {\n        const compiled = compileExpr(state, '$' + value);\n        state.outputTypes.set(name, compiled.type);\n        return `${compiled.value} AS ${quoteAlias(name)}`;\n      }\n\n      const compiled = compileFunction({ ...state, orders }, value);\n      state.outputTypes.set(name, compiled.type);\n      return compiled.value + ` AS ${quoteAlias(name)}`;\n    });\n\n    return select.join(', ');\n  },\n);","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/loot-core/src/server/aql/compiler.ts#L900-L936","documentation":"When compiling the select list, an entry that is an object must map an alias to an expression. If the object's key starts with `$` (i.e. it is a function/expression object used as a field), the compiler rejects it: every computed select expression must be given an explicit output name. This prevents producing SQL columns with no alias.","triggerScenarios":"Writing `.select({$month: '$date'})` or `.select({'$count': ...})` in the select list without wrapping it as `{alias: {$month: '$date'}}`.","commonSituations":"Trying to select a computed value directly (as in SQL `SELECT month(date)`), forgetting that AQL requires named expressions in the select list.","solutions":["Name the expression by wrapping it: `{month: {$month: '$date'}}`.","Only use `$`-prefixed keys as the value side of the select mapping, not the key.","If you want the raw field, select it as a string: `.select('date')` or `{date: 'date'}`."],"exampleFix":"// before\n.select({$month: '$date'})\n// after\n.select({month: {$month: '$date'}})","handlingStrategy":"validation","validationCode":"function assertNamedSelects(selects) {\n  for (const s of selects) {\n    if (typeof s === 'object' && s !== null && Object.keys(s).some(k => k.startsWith('$'))) {\n      throw new Error('Computed select expressions must be named: {alias: {...}}');\n    }\n  }\n}","typeGuard":"const isNamedSelect = (s) => typeof s === 'object' && s !== null && Object.keys(s).every(k => !k.startsWith('$'));","tryCatchPattern":null,"preventionTips":["Always give computed select expressions an alias object.","Reserve $-keys for the value side of the select mapping.","Wrap common expressions (month, count) in named helper factories."],"tags":["aql","query-compiler","alias-required"],"backgroundTag":"unaliased-select-expression","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}