Repository: diesel-rs/diesel
File: diesel_cli/src/infer_schema_internals/pg.rs (Rust)

Code before:
        columns
            .select((
                column_name,
                coalesce_strict(domain_name, udt_name),
                coalesce_maybe(domain_schema, udt_schema.nullable()),
                __is_nullable,
                character_maximum_length,
                col_description(regclass(table), ordinal_position),
            ))
            .filter(table_name.eq(&table.sql_name))
            .filter(table_schema.eq(schema_name))
            .into_boxed()
    } else {
        columns
            .select((
                column_name,
                udt_name,
                udt_schema.nullable(),
                __is_nullable,
                character_maximum_length,
                col_description(regclass(table), ordinal_position),
            ))
            .filter(table_name.eq(&table.sql_name))
            .filter(table_schema.eq(schema_name))
            .into_boxed()
    };

    match column_sorting {
        ColumnSorting::OrdinalPosition => query.order(ordinal_position).load(conn),
        ColumnSorting::Name => query.order(column_name).load(conn),
    }
}

impl<ST> Queryable<ST, Pg> for ColumnInformation
where
    (
        String,
        String,
        Option<String>,
        String,
        Option<i32>,
        Option<String>,
    ): FromStaticSqlRow<ST, Pg>,
{
    type Row = (
        String,
        String,
        Option<String>,
        String,
        Option<i32>,
        Option<String>,

Review comment (suggestion):
looks like you might be able to box just the expression part (see [`BoxableExpression`](https://docs.diesel.rs/master/diesel/expression/trait.BoxableExpression.html))

Code after:

    let schema_name = match table.schema {
        Some(ref name) => Cow::Borrowed(name),
        None => Cow::Owned(Pg::default_schema(conn)?),
    };

    let query = columns
        .select((
            column_name,
            udt_name,
            udt_schema.nullable(),
            domain_name,
            domain_schema.nullable(),
            __is_nullable,
            character_maximum_length,
            col_description(regclass(table), ordinal_position),
        ))
        .filter(table_name.eq(&table.sql_name))
        .filter(table_schema.eq(schema_name));

    let rows: Vec<Row> = match column_sorting {
        ColumnSorting::OrdinalPosition => query.order(ordinal_position).load(conn),
        ColumnSorting::Name => query.order(column_name).load(conn),
    }?;

    rows.into_iter()
        .map(|row| {
            let (type_name, type_schema) = row
                .domain_name
                .filter(|name| {
                    domains_as_custom_types
                        .iter()
                        .any(|regex| regex.is_match(name))
                })
                .map(|name| (name, row.domain_schema))
                .unwrap_or((row.type_name, row.type_schema));

            let max_length = row
                .max_length
                .map(|n| {
                    n.try_into().map_err(|e| {
                        diesel::result::Error::DeserializationError(
                            format!("Max column length can't be converted to u64: {e} (got: {n})")
                                .into(),
                        )
                    })
                })
                .transpose()?;

            Ok(ColumnInformation::new(
                row.column_name,