SeaQL/sea-orm · error
cannot apply alias for Column with asterisk
Error message
cannot apply alias for Column with asterisk
What it means
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.
Source
Thrown at src/query/combine.rs:58
select_def!(SelectF, "F_");
impl<E> Select<E>
where
E: EntityTrait,
{
pub(crate) fn apply_alias(mut self, pre: &str) -> Self {
self.query().exprs_mut_for_each(|sel| {
match &sel.alias {
Some(alias) => {
let alias = format!("{}{}", pre, alias.to_string().as_str());
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());
}View on GitHub (pinned to e29bcd1b41)
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
Example fix
// before let select = SelectTwo::new(...); // select expr is Column(ColumnRef::Asterisk) query.select_also(post::Entity); // after let mut query = ...; // QuerySelect query query.column(user::COLUMN.id).column(user::COLUMN.name); query.select_also(post::Entity);
Defensive patterns
Strategy: validation
Validate before calling
use sea_query::SimpleExpr;
fn is_asterisk_select(expr: &SimpleExpr) -> bool {
matches!(expr, SimpleExpr::Column(c) if c.column().is_none())
}
// assert !select_exprs.iter().any(is_asterisk_select); Type guard
fn is_concrete_column(expr: &SimpleExpr) -> bool {
match expr {
SimpleExpr::Column(c) => c.column().is_some(),
_ => false,
}
} Try / catch
// Rust panic, not catchable like exceptions; assert preconditions instead assert!(!has_asterisk(&query), "select_also requires named columns, not asterisk");
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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 AsEnum with expr other than Column
- 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/c58e161db60b70d1.
Report an issue: GitHub.