Skip to main content

uqa_execution/mutation/
errors.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Storage failure context for mutation execution.
8use uqa_core::DocId;
9use uqa_sql::SQLError;
10
11pub use uqa_sql::catalog::errors::dml_storage_error;
12
13pub use crate::storage_errors::storage_error as identifier_storage_error;
14
15pub fn missing_document_error(action: &str, table: &str, doc_id: DocId) -> SQLError {
16    SQLError::Internal(format!(
17        "{action}: document {doc_id} listed by table `{table}` disappeared during the statement"
18    ))
19}
20
21/// A row that an UPDATE, DELETE or MERGE reached was modified by a statement that the command's own triggers or functions started, which `PostgreSQL` finds under a later command id than the command's (`TM_SelfModified`). `operation` names what the command does to the row as the error does: `updated`, `deleted`, or `updated or deleted`.
22pub fn triggered_modification_error(operation: &str) -> SQLError {
23    SQLError::Diagnostic {
24        sqlstate: "27000".into(),
25        message: format!(
26            "tuple to be {operation} was already modified by an operation triggered by the current command"
27        ),
28        detail: None,
29        hint: Some(
30            "Consider using an AFTER trigger instead of a BEFORE trigger to propagate changes to other rows."
31                .into(),
32        ),
33    }
34}