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

Code before:

    Regclass::new(<String as AsExpression<sql_types::Text>>::as_expression(
        table_name,
    ))
}

pub fn get_table_data(
    conn: &mut PgConnection,
    table: &TableName,
    column_sorting: &ColumnSorting,
    domain_types_enabled: bool,
) -> QueryResult<Vec<ColumnInformation>> {
    use self::information_schema::columns::dsl::*;
    use diesel::sql_types::{Nullable, SingleValue, Text};

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

    let (select_name, select_schema) = if domain_types_enabled {
        define_sql_function!(#[sql_name = "coalesce"] fn coalesce_maybe<T: SingleValue>(x: Nullable<T>, y: Nullable<T>) -> Nullable<T>);
        define_sql_function!(#[sql_name = "coalesce"] fn coalesce_strict<T: SingleValue>(x: Nullable<T>, y: T) -> T);

        type BoxedTextExpr = Box<dyn BoxableExpression<columns, Pg, SqlType = Text>>;
        type BoxedMaybeTextExpr = Box<dyn BoxableExpression<columns, Pg, SqlType = Text>>;

        (
            Box::new(coalesce_strict(domain_name, udt_name)) as BoxedTextExpr,
            Box::new(coalesce_maybe(domain_schema, udt_schema.nullable())) as BoxedMaybeTextExpr,
        )
    } else {
        (
            Box::new(udt_name) as BoxedTextExpr,
            Box::new(udt_schema.nullable()) as BoxedMaybeTextExpr,
        )
    };

    let query = columns
        .select((
            column_name,
            select_name,
            select_schema,
            __is_nullable,
            character_maximum_length,
            col_description(regclass(table), ordinal_position),
        ))
        .filter(table_name.eq(&table.sql_name))
        .filter(table_schema.eq(schema_name));

    match column_sorting {

Review comment (suggestion):
Haha I was like, how does this work without the `Nullable<Text>` here?
The answer is it doesn't 😅
```
 error[E0271]: type mismatch resolving `<coalesce_maybe<Text, domain_schema, Nullable<udt_schema>> as Expression>::SqlType == Text`
   --> diesel_cli/src/infer_schema_internals/pg.rs:112:13
    |
112 |             Box::new(coalesce_maybe(domain_schema, udt_schema.nullable())) as BoxedMaybeTextExpr,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Text`, found `Nullable<Text>`
    |
    = note: expected struct `diesel::sql_types::Text`
               found struct `diesel::sql_types::Nullable<diesel::sql_types::Text>`
```

Code after:
    Regclass::new(<String as AsExpression<sql_types::Text>>::as_expression(
        table_name,
    ))
}

pub fn get_table_data(
    conn: &mut PgConnection,
    table: &TableName,
    column_sorting: &ColumnSorting,
    domains_as_custom_types: &[&regex::Regex],
) -> QueryResult<Vec<ColumnInformation>> {
    use self::information_schema::columns::dsl::*;

    #[derive(Queryable)]
    struct Row {
        column_name: String,
        type_name: String,
        type_schema: Option<String>,
        domain_name: Option<String>,
        domain_schema: Option<String>,
        nullable: String,
        max_length: Option<i32>,
        comment: Option<String>,
    }

    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| {