SeaQL/sea-orm · error

cannot apply alias for Column with asterisk

Error message

cannot apply alias for Column with asterisk

What it means

Select::apply_alias() prefixes each selected column's alias, but a selection whose expression is a Column with the asterisk wildcard (e.g. Column::Asterisk / select all columns) has no single concrete column to prefix, so it is rejected. The at-fault input is a query selecting an asterisk column being passed through select_also/select_with-style calls that need aliased results.

Source

Thrown at sea-orm-sync/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

  1. Select explicit columns instead of the asterisk wildcard before using select_also/select_with/select_two_required.
  2. Expand the wildcard into the entity's individual columns manually so each gets its own alias.
  3. Construct the aliased join query directly with join + column selections instead of relying on apply_alias.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at sea-orm-sync/src/query/combine.rs:58 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/b1cfc69b91510b61. Report an issue: GitHub.