uqa_sql/ast/sequence_declaration.rs
1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! The options a sequence declaration writes, as written.
8
9use super::ColumnType;
10use serde::{Deserialize, Serialize};
11
12/// The options a `CREATE SEQUENCE`, or the declaration of an identity column, writes, kept as written. `PostgreSQL` reads their values and derives the omitted ones when it creates the sequence, in an order of its own.
13#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
14pub struct SequenceDeclaration {
15 /// `AS type`.
16 pub data_type: Option<ColumnType>,
17 /// `INCREMENT [BY] value`.
18 pub increment: Option<SequenceOptionValue>,
19 /// `CYCLE` or `NO CYCLE`.
20 pub cycle: Option<bool>,
21 /// `MAXVALUE value`, or `NO MAXVALUE` as an absent value.
22 pub max_value: Option<SequenceOptionValue>,
23 /// `MINVALUE value`, or `NO MINVALUE` as an absent value.
24 pub min_value: Option<SequenceOptionValue>,
25 /// `START [WITH] value`.
26 pub start: Option<SequenceOptionValue>,
27 /// `RESTART [WITH value]`, a bare `RESTART` as an absent value: the value the first `nextval` returns, instead of the start.
28 pub restart: Option<SequenceOptionValue>,
29 /// `CACHE value`.
30 pub cache: Option<SequenceOptionValue>,
31 /// `OWNED BY`, as the written name: `NONE`, or a relation and one of its columns.
32 pub owned_by: Option<Vec<String>>,
33}
34
35/// A sequence option's value as the parser keeps it, before it is read as a 64-bit integer.
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub enum SequenceOptionValue {
38 /// No value: `NO MINVALUE`, `NO MAXVALUE` or a bare `RESTART`.
39 Absent,
40 /// An integer the parser read.
41 Integer(i64),
42 /// A number the parser kept as written: one outside the 32-bit range, or with a fraction or an exponent.
43 Text(String),
44}