1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use serde_repr::{Deserialize_repr, Serialize_repr};
4
5#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
6#[repr(u8)]
7pub enum TransactionStmtKind {
8 Begin,
9 Start,
11 Commit,
12 Rollback,
13 Savepoint,
14 Release,
15 RollbackTo,
16 Prepare,
17 CommitPrepared,
18 RollbackPrepared,
19}
20
21#[derive(Debug, Deserialize, Serialize)]
22pub struct TransactionStmt {
23 pub kind: TransactionStmtKind,
24}
25
26#[derive(Debug, Deserialize, Serialize)]
27pub struct RawStmt {
28 pub stmt: Stmt,
29 #[serde(default)]
30 pub stmt_location: i32,
31 pub stmt_len: Option<i32>,
33}
34
35#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
36#[repr(u8)]
37pub enum SetOperation {
38 None,
39 Union,
40 Intersect,
41 Except,
42}
43
44impl Default for SetOperation {
45 fn default() -> Self {
46 Self::None
47 }
48}
49
50#[derive(Debug, Deserialize, Serialize)]
51pub enum SelectChild {
52 SelectStmt(SelectStmt),
53}
54
55#[derive(Debug, Deserialize, Serialize)]
56pub struct SelectStmt {
57 #[serde(rename = "distinctClause")]
63 pub distinct_clause: Option<Value>,
64 #[serde(rename = "intoClause")]
66 pub into_clause: Option<Value>,
67 #[serde(rename = "targetList")]
69 pub target_list: Option<Vec<Value>>,
70 #[serde(rename = "fromClause")]
72 pub from_clause: Option<Value>,
73 #[serde(rename = "whereClause")]
75 pub where_clause: Option<Value>,
76 #[serde(rename = "groupClause")]
78 pub group_clause: Option<Value>,
79 #[serde(rename = "havingClause")]
81 pub having_clause: Option<Value>,
82 #[serde(rename = "windowClause")]
84 pub window_clause: Option<Value>,
85
86 #[serde(rename = "valuesLists")]
96 values_lists: Option<Value>,
97
98 #[serde(rename = "sortClause")]
104 sort_clause: Option<Value>,
105 #[serde(rename = "limitOffset")]
107 limit_offset: Option<Value>,
108 #[serde(rename = "limitCount")]
110 limit_count: Option<Value>,
111 #[serde(rename = "lockingClause")]
113 locking_clause: Option<Value>,
114 #[serde(rename = "withClause")]
116 with_clause: Option<Value>,
117
118 #[serde(default)]
123 pub op: SetOperation,
124 #[serde(default)]
126 pub all: bool,
127 pub larg: Option<Box<SelectChild>>,
129 pub rarg: Option<Box<SelectChild>>,
131}
132
133#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
135#[repr(u8)]
136pub enum SortByDir {
137 Default,
138 Asc,
139 Desc,
140 Using,
142}
143
144impl Default for SortByDir {
145 fn default() -> Self {
146 Self::Default
147 }
148}
149
150#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
151#[repr(u8)]
152pub enum SortByNulls {
153 Default,
154 First,
155 Last,
156}
157
158impl Default for SortByNulls {
159 fn default() -> Self {
160 Self::Default
161 }
162}
163
164#[derive(Debug, Deserialize, Serialize)]
165pub struct IndexElem {
166 name: String,
168 expr: Option<String>,
170 indexcolname: Option<String>,
172 collation: Option<Value>,
174 #[serde(default)]
176 opclass: Vec<Value>,
177 #[serde(default)]
179 ordering: SortByDir,
180 #[serde(default)]
182 nulls_ordering: SortByNulls,
183}
184
185#[derive(Debug, Deserialize, Serialize)]
186pub enum IndexParams {
187 IndexElem(IndexElem),
188}
189
190#[derive(Debug, Deserialize, Serialize)]
191pub struct RangeVar {
192 pub catalogname: Option<String>,
194 pub schemaname: Option<String>,
196 pub relname: String,
198 pub inh: bool,
200 pub relpersistence: String,
202 pub alias: Option<Value>,
204 pub location: i32,
206}
207
208#[derive(Debug, Deserialize, Serialize)]
209pub enum RelationKind {
210 RangeVar(RangeVar),
211}
212
213#[derive(Debug, Deserialize, Serialize)]
214pub struct IndexStmt {
215 #[serde(rename = "accessMethod")]
217 pub access_method: String,
218 pub idxname: String,
220 #[serde(rename = "indexParams")]
221 pub index_params: Vec<IndexParams>,
222 pub relation: RelationKind,
224 #[serde(default)]
225 pub concurrent: bool,
226 #[serde(default)]
228 pub unique: bool,
229 #[serde(default)]
231 pub primary: bool,
232 #[serde(default)]
234 pub isconstraint: bool,
235 #[serde(default)]
237 pub deferrable: bool,
238 #[serde(default)]
240 pub initdeferred: bool,
241 #[serde(default)]
243 pub transformed: bool,
244 #[serde(default)]
247 pub if_not_exists: bool,
248 #[serde(rename = "tableSpace")]
250 pub table_space: Option<String>,
251}
252
253#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
257#[repr(u8)]
258pub enum ObjectType {
259 AccessMethod,
260 Aggregate,
261 Amop,
262 Amproc,
263 Attribute,
265 Cast,
266 Column,
267 Collation,
268 Conversion,
269 Database,
270 Default,
271 Defacl,
272 Domain,
273 Domconstraint,
274 EventTrigger,
275 Extension,
276 Fdw,
277 ForeignServer,
278 ForeignTable,
279 Function,
280 Index,
281 Language,
282 Largeobject,
283 Matview,
284 Opclass,
285 Operator,
286 Opfamily,
287 Policy,
288 Publication,
289 PublicationRel,
290 Role,
291 Rule,
292 Schema,
293 Sequence,
294 Subscription,
295 StatisticExt,
296 TabConstraint,
297 Table,
298 Tablespace,
299 Transform,
300 Trigger,
301 TsConfiguration,
302 TsDictionary,
303 TsParser,
304 TsTemplate,
305 Type,
306 UserMapping,
307 View,
308}
309
310#[derive(Debug, Deserialize, Serialize)]
317pub enum AlterTableCmds {
318 AlterTableCmd(AlterTableCmd),
319}
320
321#[derive(Debug, Deserialize, Serialize)]
322pub struct AlterTableStmt {
323 pub cmds: Vec<AlterTableCmds>,
324 pub relation: RelationKind,
325 pub relkind: ObjectType,
326 #[serde(default)]
327 pub missing_ok: bool,
328}
329
330#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
331#[repr(u8)]
332pub enum DropBehavior {
333 Restrict,
335 DropCascade,
337}
338impl Default for DropBehavior {
339 fn default() -> Self {
340 Self::Restrict
341 }
342}
343
344#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
345#[repr(u8)]
346pub enum AlterTableType {
347 AddColumn,
349 AddColumnRecurse,
351 AddColumnToView,
353 ColumnDefault,
355 DropNotNull,
357 SetNotNull,
359 SetStatistics,
361 SetOptions,
363 ResetOptions,
365 SetStorage,
367 DropColumn,
369 DropColumnRecurse,
371 AddIndex,
373 ReAddIndex,
375 AddConstraint,
377 AddConstraintRecurse,
379 ReAddConstraint,
381 AlterConstraint,
383 ValidateConstraint,
385 ValidateConstraintRecurse,
387 ProcessedConstraint,
389 AddIndexConstraint,
391 DropConstraint,
393 DropConstraintRecurse,
395 ReAddComment,
397 AlterColumnType,
399 AlterColumnGenericOptions,
401 ChangeOwner,
403 ClusterOn,
405 DropCluster,
407 SetLogged,
409 SetUnLogged,
411 AddOids,
413 AddOidsRecurse,
415 DropOids,
417 SetTableSpace,
419 SetRelOptions,
421 ResetRelOptions,
423 ReplaceRelOptions,
425 EnableTrig,
427 EnableAlwaysTrig,
429 EnableReplicaTrig,
431 DisableTrig,
433 EnableTrigAll,
435 DisableTrigAll,
437 EnableTrigUser,
439 DisableTrigUser,
441 EnableRule,
443 EnableAlwaysRule,
445 EnableReplicaRule,
447 DisableRule,
449 AddInherit,
451 DropInherit,
453 AddOf,
455 DropOf,
457 ReplicaIdentity,
459 EnableRowSecurity,
461 DisableRowSecurity,
463 ForceRowSecurity,
465 NoForceRowSecurity,
467 GenericOptions,
469 AttachPartition,
471 DetachPartition,
473 AddIdentity,
475 SetIdentity,
477 DropIdentity,
479}
480
481#[derive(Debug, Deserialize, Serialize)]
482pub enum ColumnDefConstraint {
483 Constraint(Constraint),
484}
485
486#[derive(Debug, Deserialize, Serialize)]
487pub struct PGString {
488 pub str: String,
489}
490
491#[derive(Debug, Deserialize, Serialize)]
492pub enum QualifiedName {
493 String(PGString),
494}
495
496#[derive(Debug, Deserialize, Serialize)]
510pub struct TypeName {
511 #[serde(default)]
513 pub names: Vec<QualifiedName>,
514 #[serde(rename = "typeOid")]
516 pub type_oid: Option<Value>,
517 #[serde(default)]
519 pub setof: bool,
520 #[serde(default)]
522 pub pct_type: bool,
523 #[serde(default)]
525 pub typmods: Vec<Value>,
526 pub typemod: i32,
528 #[serde(rename = "arrayBounds", default)]
529 pub array_bounds: Vec<Value>,
530 pub location: i32,
532}
533
534#[derive(Debug, Deserialize, Serialize)]
535pub enum ColumnDefTypeName {
536 TypeName(TypeName),
537}
538
539#[derive(Debug, Deserialize, Serialize)]
540pub struct ColumnDef {
541 pub colname: Option<String>,
556 #[serde(rename = "typeName")]
557 pub type_name: ColumnDefTypeName,
558 #[serde(default)]
559 pub constraints: Vec<ColumnDefConstraint>,
560 #[serde(default)]
562 pub is_local: bool,
563 pub location: i32,
564}
565
566#[derive(Debug, Deserialize, Serialize)]
567pub enum AlterTableDef {
568 Constraint(Constraint),
569 ColumnDef(ColumnDef),
570 #[serde(rename = "A_Const")]
571 Constant(Value),
572 ReplicaIdentityStmt(Value),
573}
574
575#[derive(Debug, Deserialize, Serialize)]
576pub struct AlterTableCmd {
577 pub subtype: AlterTableType,
579 pub name: Option<String>,
581 pub def: Option<AlterTableDef>,
583 #[serde(default)]
584 pub behavior: DropBehavior,
585 #[serde(default)]
588 pub missing_ok: bool,
589}
590
591#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
592#[repr(u8)]
593pub enum ConstrType {
594 Null,
596 NotNull,
597 Default,
598 Identity,
599 Check,
600 Primary,
601 Unique,
602 Exclusion,
603 Foreign,
604 AttrDeferrable,
606 AttrNotDeferrable,
607 AttrDeferred,
608 AttrImmediate,
609}
610
611#[derive(Debug, Deserialize, Serialize)]
612pub struct Constraint {
613 pub contype: ConstrType,
614
615 pub location: i32,
621
622 pub raw_expr: Option<Value>,
626 pub keys: Option<Value>,
632
633 pub indexname: Option<String>,
640 #[serde(default)]
656 pub skip_validation: bool,
657 #[serde(default)]
659 pub initially_valid: bool,
660}
661
662#[derive(Debug, Deserialize, Serialize)]
663pub struct RenameStmt {
664 pub newname: String,
666 pub behavior: DropBehavior,
667 pub relation: Option<RelationKind>,
669 #[serde(rename = "relationType")]
670 pub relation_type: ObjectType,
671 #[serde(rename = "renameType")]
672 pub rename_type: ObjectType,
673 pub subname: Option<String>,
675 }
677
678#[derive(Debug, Deserialize, Serialize)]
679pub enum TableElt {
680 ColumnDef(ColumnDef),
681}
682
683#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
685#[repr(u8)]
686pub enum OnCommitAction {
687 Noop,
689 PreserveRows,
691 DeleteRows,
693 Drop,
695}
696
697#[derive(Debug, Deserialize, Serialize)]
698pub struct CreateStmt {
699 pub relation: RelationKind,
701 #[serde(rename = "tableElts")]
703 pub table_elts: Vec<TableElt>,
704 #[serde(rename = "inhRelations")]
706 #[serde(default)]
707 pub inh_relations: Vec<Value>,
708 pub partbound: Option<Value>,
710 pub partspec: Option<Value>,
712 #[serde(rename = "ofTypename")]
714 pub of_typename: Option<Value>,
715 #[serde(default)]
717 pub constraints: Vec<Constraint>,
718 #[serde(default)]
720 pub options: Vec<Value>,
721 pub oncommit: OnCommitAction,
723 pub tablespacename: Option<String>,
725 #[serde(default)]
727 pub if_not_exists: bool,
728}
729
730#[derive(Debug, Deserialize, Serialize)]
731pub enum RootStmt {
732 RawStmt(RawStmt),
733}
734
735#[allow(clippy::large_enum_variant)]
738#[derive(Debug, Deserialize, Serialize)]
739pub enum Stmt {
740 TransactionStmt(TransactionStmt),
741 SelectStmt(SelectStmt),
742 IndexStmt(IndexStmt),
743 AlterTableStmt(AlterTableStmt),
744 RenameStmt(RenameStmt),
745 CreateStmt(CreateStmt),
746 InsertStmt(Value),
747 UpdateStmt(Value),
748 DeleteStmt(Value),
749 CreateSchemaStmt(Value),
750 AlterDomainStmt(Value),
751 GrantStmt(Value),
752 GrantRoleStmt(Value),
753 AlterDefaultPrivilegesStmt(Value),
754 CopyStmt(Value),
755 VariableSetStmt(Value),
756 VariableShowStmt(Value),
757 CreateTableSpaceStmt(Value),
758 DropTableSpaceStmt(Value),
759 CreateExtensionStmt(Value),
760 AlterExtensionStmt(Value),
761 DropStmt(Value),
762 AlterObjectSchemaStmt(Value),
763 AlterExtensionContentsStmt(Value),
764 CreateFdwStmt(Value),
765 AlterFdwStmt(Value),
766 CreateForeignServerStmt(Value),
767 AlterForeignServerStmt(Value),
768 CreateForeignTableStmt(Value),
769 CreateUserMappingStmt(Value),
770 AlterUserMappingStmt(Value),
771 DropUserMappingStmt(Value),
772 ImportForeignSchemaStmt(Value),
773 CreatePolicyStmt(Value),
774 AlterPolicyStmt(Value),
775 CreateAmStmt(Value),
776 CreateTrigStmt(Value),
777 CreateEventTrigStmt(Value),
778 AlterEventTrigStmt(Value),
779 CreateFunctionStmt(Value),
780 AlterFunctionStmt(Value),
781 CreatePLangStmt(Value),
782 CreateRoleStmt(Value),
783 AlterRoleStmt(Value),
784 AlterRoleSetStmt(Value),
785 DropRoleStmt(Value),
786 CreateSeqStmt(Value),
787 AlterSeqStmt(Value),
788 DefineStmt(Value),
789 CreateDomainStmt(Value),
790 CreateOpClassStmt(Value),
791 CreateOpFamilyStmt(Value),
792 AlterOpFamilyStmt(Value),
793 TruncateStmt(Value),
794 CommentStmt(Value),
795 SecLabelStmt(Value),
796 DeclareCursorStmt(Value),
797 ClosePortalStmt(Value),
798 FetchStmt(Value),
799 CreateStatsStmt(Value),
800 ExplainStmt(Value),
801 AlterOwnerStmt(Value),
802 DoStmt(Value),
803 AlterObjectDependsStmt(Value),
804 AlterOperatorStmt(Value),
805 RuleStmt(Value),
806 NotifyStmt(Value),
807 ListenStmt(Value),
808 UnlistenStmt(Value),
809 CompositeTypeStmt(Value),
810 CreateEnumStmt(Value),
811 CreateRangeStmt(Value),
812 AlterEnumStmt(Value),
813 ViewStmt(Value),
814 LoadStmt(Value),
815 CreatedbStmt(Value),
816 AlterDatabaseStmt(Value),
817 AlterDatabaseSetStmt(Value),
818 DropdbStmt(Value),
819 AlterSystemStmt(Value),
820 ClusterStmt(Value),
821 VacuumStmt(Value),
822 CreateTableAsStmt(Value),
823 RefreshMatViewStmt(Value),
824 CheckPointStmt(Value),
825 DiscardStmt(Value),
826 LockStmt(Value),
827 ConstraintsSetStmt(Value),
828 ReindexStmt(Value),
829 CreateConversionStmt(Value),
830 CreateCastStmt(Value),
831 CreateTransformStmt(Value),
832 PrepareStmt(Value),
833 ExecuteStmt(Value),
834 DeallocateStmt(Value),
835 DropOwnedStmt(Value),
836 ReassignOwnedStmt(Value),
837 AlterTSDictionaryStmt(Value),
838 AlterTSConfigurationStmt(Value),
839 CreatePublicationStmt(Value),
840 AlterPublicationStmt(Value),
841 CreateSubscriptionStmt(Value),
842 AlterSubscriptionStmt(Value),
843 DropSubscriptionStmt(Value),
844}