{"record":{"id":"642ce66da0688f32","repo":"SeaQL/sea-orm","slug":"cannot-apply-alias-for-expr-other-than-column-or-a-642ce6","errorCode":null,"errorMessage":"cannot apply alias for expr other than Column or AsEnum","messagePattern":"cannot apply alias for expr other than Column or AsEnum","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/combine.rs","lineNumber":72,"sourceCode":"                    let col = match &sel.expr {\n                        SimpleExpr::Column(col_ref) => match col_ref.column() {\n                            Some(col) => col,\n                            None => {\n                                panic!(\"cannot apply alias for Column with asterisk\");\n                            }\n                        },\n                        SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {\n                            SimpleExpr::Column(col_ref) => match col_ref.column() {\n                                Some(col) => col,\n                                None => {\n                                    panic!(\"cannot apply alias for AsEnum with asterisk\")\n                                }\n                            },\n                            _ => {\n                                panic!(\"cannot apply alias for AsEnum with expr other than Column\")\n                            }\n                        },\n                        _ => panic!(\"cannot apply alias for expr other than Column or AsEnum\"),\n                    };\n                    let alias = format!(\"{}{}\", pre, col.to_string().as_str());\n                    sel.alias = Some(alias.into_iden());\n                }\n            };\n        });\n        self\n    }\n\n    /// Selects extra Entity and returns it together with the Entity from `Self`\n    pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>\n    where\n        F: EntityTrait,\n    {\n        self = self.apply_alias(SelectA.as_str());\n        SelectTwo::new(self.into_query())\n    }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/query/combine.rs#L54-L90","documentation":"The catch-all arm of apply_alias's match panics with this message for any select expression that is neither a Column nor an AsEnum-wrapped Column. The combinator aliases every selected column by name, so non-column expressions are unsupported by design.","triggerScenarios":"Calling select_also / select_with / select_two_required / left_join_linked on a query whose select list contains any non-column expression such as Function, Case, Binary, SubQuery or Keyword exprs.","commonSituations":"Aggregates (MAX, COUNT) or expressions (col + 1) added to a combined query; template-generated selects containing computed fields.","solutions":["Restrict the select list of these combinators to plain columns","Use .expr_as(expr, alias) with explicit aliasing instead of the combinator's automatic aliasing","Split computed fields into their own unaliased query and join results in application code"],"exampleFix":"// before\nquery.expr(Expr::col(user::COLUMN.age).add(1));\nquery.select_also(post::Entity);\n// after\nquery.column(user::COLUMN.age);\nlet age_plus = Expr::col(user::COLUMN.age).add(1); // handled separately","handlingStrategy":"validation","validationCode":"fn supports_auto_alias(expr: &SimpleExpr) -> bool {\n    matches!(expr, SimpleExpr::Column(_) | SimpleExpr::AsEnum(_, _))\n}","typeGuard":"fn is_column_like(expr: &SimpleExpr) -> bool {\n    matches!(expr, SimpleExpr::Column(_) | SimpleExpr::AsEnum(_, _))\n}","tryCatchPattern":"// pre-assert; panics cannot be caught in Rust\nassert!(sel_exprs.iter().all(supports_auto_alias), \"use explicit expr_as for non-column exprs\");","preventionTips":["Centralize select-list construction to forbid non-column exprs in combinators","Use explicit .expr_as for aggregates/expressions","Code-review generated queries for Func/Case/Binary exprs in aliased joins"],"tags":["panic","query-builder","alias","sql"],"backgroundTag":"unsupported-operation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}