1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
use crate::{ast::*, common::symbol::Symbol};
/// Represents a DDL statement to modify an existing table schema or properties (`ALTER TABLE`).
#[derive(Debug, Clone, PartialEq)]
pub struct AlterTableStmt {
/// Skip error creation if the table does not exist (`IF EXISTS`).
pub if_exist: bool,
/// The qualified name of the table to alter.
pub name: ObjectName,
/// The list of actions to perform on the table.
pub actions: Vec<AlterTableAction>,
}
/// The specific action to apply to the table in an `ALTER TABLE` statement.
#[derive(Debug, Clone, PartialEq)]
pub enum AlterTableAction {
/// Add a new column to the table (`ADD [COLUMN] [IF NOT EXISTS] column_def`).
AddColumn {
/// If `true`, does nothing if the column already exists.
if_not_exist: bool,
/// The new column definition.
column: ColumnDef,
},
/// Drop a column from the table (`DROP [COLUMN] [IF EXISTS] name [CASCADE|RESTRICT]`).
DropColumn {
/// If `true`, does nothing if the column does not exist.
if_exist: bool,
/// The column name.
name: Symbol,
/// Optional cascade/restrict behavior for dropping associated dependencies.
behaviour: Option<DropBehavior>,
},
/// Modify an existing column's definition (e.g. data type, default value).
AlterColumn {
/// The name of the column to alter.
name: Symbol,
/// The modification action to perform on this column.
action: AlterColumnAction,
},
/// Rename a column (`RENAME COLUMN old_name TO new_name`).
RenameColumn {
/// The current name of the column.
old_name: Symbol,
/// The new name for the column.
new_name: Symbol,
},
/// Add a new table-level constraint (`ADD CONSTRAINT constraint_def`).
AddConstraint(TableConstraint),
/// Drop a table-level constraint (`DROP CONSTRAINT [IF EXISTS] name [CASCADE|RESTRICT]`).
DropConstraint {
/// If `true`, does nothing if the constraint does not exist.
if_exist: bool,
/// The constraint name.
name: Symbol,
/// Optional cascade/restrict behavior for dropping dependencies.
behaviour: Option<DropBehavior>,
},
/// Rename a constraint (`RENAME CONSTRAINT old_name TO new_name`).
RenameConstraint {
/// The current constraint name.
old_name: Symbol,
/// The new name for the constraint.
new_name: Symbol,
},
/// Rename the table (`RENAME TO new_name`).
RenameTable(Symbol),
/// Change the table's schema (`SET SCHEMA new_schema`).
SetSchema(Symbol),
/// Change the table owner (`OWNER TO new_owner`).
SetOwner(Symbol),
/// Change the table's tablespace (`SET TABLESPACE new_tablespace`).
SetTableSpace(Symbol),
/// Set specific table parameters (`SET (options)`).
SetOptions(Vec<SqlOption>),
/// Reset/Remove specific table parameters (`RESET (options)`).
ResetOptions(Vec<Symbol>),
/// Add a parent table to inherit from (`INHERIT parent_table`).
Inherit(ObjectName),
/// Remove inheritance from a parent table (`NO INHERIT parent_table`).
NoInherit(ObjectName),
/// Attach a partition table (`ATTACH PARTITION partition_name FOR VALUES ...`).
AttachPartition {
/// The name of the partition table.
partition: ObjectName,
/// The partition boundary specification.
for_values: PartitionBound,
},
/// Detach a partition table (`DETACH PARTITION partition_name`).
DetachPartition(ObjectName),
}
/// The specific action to apply to a column in an `ALTER COLUMN` statement.
#[derive(Debug, Clone, PartialEq)]
pub enum AlterColumnAction {
/// Change the column's data type, optionally changing collation or using a conversion expression (`SET DATA TYPE type [COLLATE c] [USING expr]`).
SetType {
/// The new data type.
data_type: DataType,
/// Optional custom collation name.
collation: Option<Symbol>,
/// Optional expression to convert current data to the new type.
using: Option<Expr>,
},
/// Set a new default value for the column (`SET DEFAULT expr`).
SetDefault(Expr),
/// Remove the column's default value (`DROP DEFAULT`).
DropDefault,
/// Enforce that the column cannot store nulls (`SET NOT NULL`).
SetNotNull,
/// Allow the column to store nulls (`DROP NOT NULL`).
DropNotNull,
/// Set statistical logging target (`SET STATISTICS integer`).
SetStatistics(i64),
/// Set column-specific options.
SetOptions(Vec<SqlOption>),
/// Reset/Remove column-specific options.
ResetOptions(Vec<Symbol>),
/// Change the storage mode of the column (e.g. `PLAIN`, `MAIN`).
SetStorage(ColumnStorage),
}
/// PostgreSQL column storage options.
#[derive(Debug, Clone, PartialEq)]
pub enum ColumnStorage {
/// Plain values stored inline (no compression or out-of-line storage).
Plain,
/// Compression is allowed, inline storage only.
External,
/// Compression and out-of-line storage are allowed (default for most compressible types).
Extended,
/// Compression is allowed, but out-of-line storage is used only as a last resort.
Main,
}
/// Represents the partition bound values for list, range, or hash partitioning.
#[derive(Debug, Clone, PartialEq)]
pub enum PartitionBound {
/// Boundary for list partitioning (`IN (value1, ...)`).
In(Vec<Expr>),
/// Boundaries for range partitioning (`FROM (low, ...) TO (high, ...)`).
FromTo {
/// The lower boundary list.
from: Vec<PartitionBoundValue>,
/// The upper boundary list.
to: Vec<PartitionBoundValue>,
},
/// Boundary for hash partitioning (`WITH (MODULUS m, REMAINDER r)`).
With(Vec<Expr>),
/// Default partition catch-all for list/range partitioning (`DEFAULT`).
Default,
}
/// A boundary value limit in a range partition definition (e.g. `MINVALUE` or a expression).
#[derive(Debug, Clone, PartialEq)]
pub enum PartitionBoundValue {
/// Evaluated scalar expression boundary value.
Expr(Expr),
/// Minimum possible value representation (`MINVALUE`).
Minvalue,
/// Maximum possible value representation (`MAXVALUE`).
Maxvalue,
}