Skip to main content

uqa_sql/ast/
overriding.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! `INSERT ... OVERRIDING` selection of identity column values.
8
9use serde::{Deserialize, Serialize};
10
11/// Which value an `INSERT` writes to an identity column it supplies a value for. Without the clause a supplied value is written to a `GENERATED BY DEFAULT` identity column and rejected for a `GENERATED ALWAYS` one.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "snake_case")]
14pub enum OverridingKind {
15    /// `OVERRIDING SYSTEM VALUE`: write the supplied value, also to a `GENERATED ALWAYS` column.
16    SystemValue,
17    /// `OVERRIDING USER VALUE`: discard the supplied value and draw the column's next sequence value.
18    UserValue,
19}
20
21impl OverridingKind {
22    /// The SQL clause, as `PostgreSQL` prints it.
23    #[must_use]
24    pub const fn sql(self) -> &'static str {
25        match self {
26            Self::SystemValue => "OVERRIDING SYSTEM VALUE",
27            Self::UserValue => "OVERRIDING USER VALUE",
28        }
29    }
30}