Skip to content

Comments

fix: make AsEnum quoted to get the correct enum in postgres#860

Merged
tyt2y3 merged 3 commits intoSeaQL:quote-enumfrom
MedHeikelBouzayene:fix/as_enum_quoted_postgres
Apr 16, 2025
Merged

fix: make AsEnum quoted to get the correct enum in postgres#860
tyt2y3 merged 3 commits intoSeaQL:quote-enumfrom
MedHeikelBouzayene:fix/as_enum_quoted_postgres

Conversation

@MedHeikelBouzayene
Copy link
Contributor

PR Info

Bug Fixes

  • Enums are always lowercased in queries as shown in the issue example

Copy link
Contributor

@ikrivosheev ikrivosheev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! LGTM!

match simple_expr {
SimpleExpr::AsEnum(type_name, expr) => {
let simple_expr = expr.clone().cast_as(SeaRc::clone(type_name));
let simple_expr = expr.clone().cast_as_quoted(SeaRc::clone(type_name), '"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use self.quote()

@tyt2y3
Copy link
Member

tyt2y3 commented Feb 16, 2025

Actually, isn't it duplicate of https://github.com/SeaQL/sea-query/pull/789/files ?

@MedHeikelBouzayene
Copy link
Contributor Author

Actually, isn't it duplicate of https://github.com/SeaQL/sea-query/pull/789/files ?

I think so, but I don't know why it was removed

@Huliiiiii
Copy link
Member

I think this was reverted at 6265311.

@tyt2y3 Could you please merge this PR? I think it breaks many people's code (if they use PascalCase enums).

@tyt2y3
Copy link
Member

tyt2y3 commented Apr 16, 2025

sorry, I vaguely remembered this could cause a breaking change in sea-orm.
I'll have to run this through SeaORM's CI

@tyt2y3 tyt2y3 changed the base branch from master to quote-enum April 16, 2025 19:42
@tyt2y3 tyt2y3 merged commit e687324 into SeaQL:quote-enum Apr 16, 2025
@tyt2y3
Copy link
Member

tyt2y3 commented Apr 16, 2025

oh, this is the problem https://github.com/SeaQL/sea-orm/actions/runs/14501664913/job/40682803243

2025-04-16T20:19:11.618739Z  INFO sqlx::query: summary="INSERT INTO \"collection\" (\"id\", …" db.statement="\n\nINSERT INTO \"collection\" (\"id\", \"name\", \"integers\", \"integers_opt\", \"teas\", \"teas_opt\", \"colors\", \"colors_opt\", \"uuid\", \"uuid_hyphenated\") VALUES ($1, CAST($2 AS citext), $3, $4, CAST($5 AS \"tea[]\"), CAST($6 AS \"tea[]\"), $7, $8, $9, $10) RETURNING \"id\", CAST(\"name\" AS text), \"integers\", \"integers_opt\", CAST(\"teas\" AS \"text[]\"), CAST(\"teas_opt\" AS \"text[]\"), \"colors\", \"colors_opt\", \"uuid\", \"uuid_hyphenated\"\n" rows_affected=0 rows_returned=0 elapsed=400.865µs elapsed_secs=0.000400865
Error: Query(SqlxError(Database(PgDatabaseError { severity: Error, code: "42704", message: "type \"tea[]\" does not exist", detail: None, hint: None, position: Some(Original(191)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") })))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enums are always lowercased in queries despire enum_name leading to type does not exist

4 participants