SeaQL/sea-orm · error
cannot apply alias for AsEnum with expr other than Column
Error message
cannot apply alias for AsEnum with expr other than Column
What it means
apply_alias only understands two shapes of select expressions: a bare Column and a Column wrapped in AsEnum. Any other expression type (function call, case, sub-query, binary op, etc.) cannot be aliased by the combinator, so it panics. This is a deliberate restriction of the select_also/select_with family.
Source
Thrown at src/query/combine.rs:69
sel.alias = Some(alias.into_iden());
}
None => {
let col = match &sel.expr {
SimpleExpr::Column(col_ref) => match col_ref.column() {
Some(col) => col,
None => {
panic!("cannot apply alias for Column with asterisk");
}
},
SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {
SimpleExpr::Column(col_ref) => match col_ref.column() {
Some(col) => col,
None => {
panic!("cannot apply alias for AsEnum with asterisk")
}
},
_ => {
panic!("cannot apply alias for AsEnum with expr other than Column")
}
},
_ => panic!("cannot apply alias for expr other than Column or AsEnum"),
};
let alias = format!("{}{}", pre, col.to_string().as_str());
sel.alias = Some(alias.into_iden());
}
};
});
self
}
/// Selects extra Entity and returns it together with the Entity from `Self`
pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>
where
F: EntityTrait,
{
self = self.apply_alias(SelectA.as_str());View on GitHub (pinned to e29bcd1b41)
Solutions
- Select only concrete columns (bare Column or AsEnum-wrapped Column) with these combinators
- Compute derived expressions in a separate query or alias them explicitly with .expr_as(...) instead of relying on apply_alias
- Post-process computed values in Rust rather than in the aliased select list
Example fix
// before
query.expr(Expr::cust("COUNT(*)"));
query.select_also(post::Entity);
// after
query.column(user::COLUMN.id);
query.select_also(post::Entity); Defensive patterns
Strategy: validation
Validate before calling
fn aliasable(expr: &SimpleExpr) -> bool {
match expr {
SimpleExpr::Column(c) => c.column().is_some(),
SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(_)),
_ => false,
}
} Type guard
fn is_column_like(expr: &SimpleExpr) -> bool {
matches!(expr, SimpleExpr::Column(_) | SimpleExpr::AsEnum(_, _))
} Try / catch
// guard before the combinator assert!(exprs.iter().all(aliasable), "only Column / AsEnum(Column) exprs are aliasable here");
Prevention
- Keep combinator select lists to plain columns
- Use .expr_as(expr, alias) for computed expressions
- Document that select_also/select_with only support column selections
When it happens
Trigger: Passing an arbitrary SimpleExpr (COUNT(*), CASE, arithmetic, Func expressions) into a select list used with select_also, select_with, select_two_required or left_join_linked.
Common situations: Developers composing aggregate or computed columns into a joined aliased query expecting automatic aliasing; migrating raw select_expr usage into the combinator API.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- cannot apply alias for Column with asterisk
- cannot apply alias for expr other than Column or AsEnum
- cannot apply alias for AsEnum with asterisk
- cannot apply alias for AsEnum with asterisk
- cannot apply alias for AsEnum with expr other than Column
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/30ffdb4d46cd218e.
Report an issue: GitHub.