{"record":{"id":"c58e161db60b70d1","repo":"SeaQL/sea-orm","slug":"cannot-apply-alias-for-column-with-asterisk-c58e16","errorCode":null,"errorMessage":"cannot apply alias for Column with asterisk","messagePattern":"cannot apply alias for Column with asterisk","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/combine.rs","lineNumber":58,"sourceCode":"select_def!(SelectF, \"F_\");\n\nimpl<E> Select<E>\nwhere\n    E: EntityTrait,\n{\n    pub(crate) fn apply_alias(mut self, pre: &str) -> Self {\n        self.query().exprs_mut_for_each(|sel| {\n            match &sel.alias {\n                Some(alias) => {\n                    let alias = format!(\"{}{}\", pre, alias.to_string().as_str());\n                    sel.alias = Some(alias.into_iden());\n                }\n                None => {\n                    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                }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/query/combine.rs#L40-L76","documentation":"apply_alias in sea-orm's combine query machinery builds an output column alias by suffixing the underlying column name. When a selected expression is a bare Column that resolves to an asterisk (wildcard), there is no concrete column name to derive an alias from, so the library panics deliberately rather than producing ambiguous SQL. It is thrown by the select_also/select_with combinator family.","triggerScenarios":"Calling select_also, select_with, select_two_required, left_join_linked (or select_also_fake) where the query's selected expression is a SimpleExpr::Column whose column() is None — i.e. a wildcard/asterisk selection such as select_all-style output.","commonSituations":"Combining a joined, aliased query after using .select_all() or leaving a default wildcard select instead of naming explicit columns; generated code that assumed asterisk selects work with aliased joins.","solutions":["Replace the wildcard/asterisk select with explicit named columns before using the select_also/select_with combinators","Use Entity::find() default full-model select rather than hand-building a select expr containing Asterisk for these combinators","Check the query's select list and assert no Asterisk column is present before calling the combinator"],"exampleFix":"// before\nlet select = SelectTwo::new(...); // select expr is Column(ColumnRef::Asterisk)\nquery.select_also(post::Entity);\n// after\nlet mut query = ...; // QuerySelect query\nquery.column(user::COLUMN.id).column(user::COLUMN.name);\nquery.select_also(post::Entity);","handlingStrategy":"validation","validationCode":"use sea_query::SimpleExpr;\nfn is_asterisk_select(expr: &SimpleExpr) -> bool {\n    matches!(expr, SimpleExpr::Column(c) if c.column().is_none())\n}\n// assert !select_exprs.iter().any(is_asterisk_select);","typeGuard":"fn is_concrete_column(expr: &SimpleExpr) -> bool {\n    match expr {\n        SimpleExpr::Column(c) => c.column().is_some(),\n        _ => false,\n    }\n}","tryCatchPattern":"// Rust panic, not catchable like exceptions; assert preconditions instead\nassert!(!has_asterisk(&query), \"select_also requires named columns, not asterisk\");","preventionTips":["Never combine select_also/select_with with wildcard or select_all-style selects","Always name explicit columns before aliased-join combinators","Add a debug assertion that every select expr resolves to a concrete column"],"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-14T05:17:10.506Z"}