Skip to content

Incorrect Quoting of Schema-Qualified Enums in cast_as_quoted #827

@mpyw

Description

@mpyw

Description

When using the cast_as_quoted function to cast schema-qualified enums (e.g., schema_name.enum_name), the generated SQL incorrectly quotes the entire identifier as "schema_name.enum_name". Instead, each part of the schema and enum should be quoted separately, like "schema_name"."enum_name", to ensure correctness.

Steps to Reproduce

  1. Define a schema-qualified enum:
    CREATE TYPE schema_name.enum_name AS ENUM ('value1', 'value2');
  2. Use SeaQuery to cast a value using cast_as_quoted:
    use sea_query::{tests_cfg::*, *};
    
    let query = Query::select()
        .expr(Func::cast_as_quoted(
            "some_value",
            Alias::new("schema_name.enum_name"),
            '"'.into(),
        ))
        .to_owned();
  3. Generate the SQL for PostgreSQL:
    assert_eq!(
        query.to_string(PostgresQueryBuilder),
        r#"SELECT CAST('some_value' AS "schema_name.enum_name")"#
    );

Expected Behavior

The SQL should be generated as:

SELECT CAST('some_value' AS "schema_name"."enum_name")

Actual Behavior

The SQL is incorrectly generated as:

SELECT CAST('some_value' AS "schema_name.enum_name")

Reproduces How Often

Always.

Versions

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions