Prepared statement errors `there is no unique or exclusion constraint matching the ON CONFLICT specification` from database but unprepared statement works · Issue #2495 · SeaQL/sea-orm · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prepared statement errors there is no unique or exclusion constraint matching the ON CONFLICT specification from database but unprepared statement works
#2495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
When running a query using on conflict update clauses, it errored from the database on execution: 2025-02-15T00:32:52.275908Z ERROR run: task::review: error=Execution Error: error returned from database: there is no unique or exclusion constraint matching the ON CONFLICT specification.
However, manually testing the interpolated query in TablePlus, the query executed successfully,
So, I tried building the query into a string first and then executing an unprepared statement in the transaction and it works fine.
The canonical path of executing the prepared statement ought to work though.
Steps to Reproduce
Migrate up the schema like so, taking liberties to ensure it builds.
Insert a record like so. Uncomment the code to reproduce the error.
ReviewComment::insert_many(comments).on_conflict(
sea_orm::sea_query::OnConflict::columns([
entity::review_comment::Column::ReviewId,
entity::review_comment::Column::ReviewStage,
entity::review_comment::Column::CriteriaId,]).target_and_where(Expr::col(entity::review_comment::Column::CommentKind).is_in([
entity::sea_orm_active_enums::ReviewCommentKind::KritiqScreening.as_enum(),
entity::sea_orm_active_enums::ReviewCommentKind::KritiqExtraction.as_enum(),]),).update_columns([
entity::review_comment::Column::AccountId,
entity::review_comment::Column::CommentStatus,
entity::review_comment::Column::InferenceReasoning,
entity::review_comment::Column::InferenceSnippets,
entity::review_comment::Column::Content,
entity::review_comment::Column::Preview,
entity::review_comment::Column::InferenceDecision,
entity::review_comment::Column::UpdatedAt,]).to_owned(),)// HACK: Using the canonical execution method, we get the error:// 2025-02-15T00:32:52.275908Z ERROR run: task::review: error=Execution Error: error returned from database: there is no unique or exclusion constraint matching the ON CONFLICT specification// So avoid it by building the query first and executing an unprepared statement.// .exec_without_returning(transaction)// .await?;.build(sea_orm::DbBackend::Postgres).to_string().pipe_deref(|sql| transaction.execute_unprepared(sql)).await?;
Expected Behavior
Executing via exec_without_returning should work.
Actual Behavior
Have to first build the query into string, and then execute an unprepared statement for it to work.
Reproduces How Often
Always reproducible.
Workarounds
Have to first build the query into string, and then execute an unprepared statement for it to work.
Reproducible Example
See above for steps to reproduce.
Versions
NeonDB Postgres 17
sea-orm = { version = "1.1.4", features = [
"debug-print",
"macros",
"runtime-tokio-rustls",
"sqlx-postgres",
] }
The text was updated successfully, but these errors were encountered:
If I had to guess, I would say that Postgres is probably expecting the partial index expression to (more or less) exactly match the one on the index itself; it's probably not enough for them to be semantically equivalent.
Compare the generated CREATE INDEX statement with the generated query. If they're the same other than the query parameter, then most likely the query parameter itself is defeating the check. You could probably consider that a Postgres bug, but sea-orm could just inline the value instead.
Description
When running a query using on conflict update clauses, it errored from the database on execution:
2025-02-15T00:32:52.275908Z ERROR run: task::review: error=Execution Error: error returned from database: there is no unique or exclusion constraint matching the ON CONFLICT specification
.However, manually testing the interpolated query in TablePlus, the query executed successfully,
So, I tried building the query into a string first and then executing an unprepared statement in the transaction and it works fine.
The canonical path of executing the prepared statement ought to work though.
Steps to Reproduce
Expected Behavior
Executing via
exec_without_returning
should work.Actual Behavior
Have to first build the query into string, and then execute an unprepared statement for it to work.
Reproduces How Often
Always reproducible.
Workarounds
Have to first build the query into string, and then execute an unprepared statement for it to work.
Reproducible Example
See above for steps to reproduce.
Versions
NeonDB Postgres 17
The text was updated successfully, but these errors were encountered: