2020use crate :: ast:: {
2121 display_comma_separated, display_separated, ConstraintCharacteristics ,
2222 ConstraintReferenceMatchKind , Expr , Ident , IndexColumn , IndexOption , IndexType ,
23- KeyOrIndexDisplay , NullsDistinctOption , ObjectName , OrderByOptions , ReferentialAction ,
23+ KeyOrIndexDisplay , NullsDistinctOption , ObjectName , ReferentialAction ,
2424} ;
2525use crate :: tokenizer:: Span ;
2626use core:: fmt;
@@ -117,12 +117,12 @@ pub enum TableConstraint {
117117 ///
118118 /// [1]: https://www.postgresql.org/docs/current/sql-altertable.html
119119 UniqueUsingIndex ( ConstraintUsingIndex ) ,
120- /// PostgreSQL `EXCLUDE` constraint.
120+ /// `EXCLUDE` constraint.
121121 ///
122122 /// `[ CONSTRAINT <name> ] EXCLUDE [ USING <index_method> ] ( <element> WITH <operator> [, ...] ) [ INCLUDE (<cols>) ] [ WHERE (<predicate>) ]`
123123 ///
124- /// See < https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE>
125- Exclusion ( ExclusionConstraint ) ,
124+ /// [PostgreSQL]( https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE)
125+ Exclude ( ExcludeConstraint ) ,
126126}
127127
128128impl From < UniqueConstraint > for TableConstraint {
@@ -161,9 +161,9 @@ impl From<FullTextOrSpatialConstraint> for TableConstraint {
161161 }
162162}
163163
164- impl From < ExclusionConstraint > for TableConstraint {
165- fn from ( constraint : ExclusionConstraint ) -> Self {
166- TableConstraint :: Exclusion ( constraint)
164+ impl From < ExcludeConstraint > for TableConstraint {
165+ fn from ( constraint : ExcludeConstraint ) -> Self {
166+ TableConstraint :: Exclude ( constraint)
167167 }
168168}
169169
@@ -178,7 +178,7 @@ impl fmt::Display for TableConstraint {
178178 TableConstraint :: FulltextOrSpatial ( constraint) => constraint. fmt ( f) ,
179179 TableConstraint :: PrimaryKeyUsingIndex ( c) => c. fmt_with_keyword ( f, "PRIMARY KEY" ) ,
180180 TableConstraint :: UniqueUsingIndex ( c) => c. fmt_with_keyword ( f, "UNIQUE" ) ,
181- TableConstraint :: Exclusion ( constraint) => constraint. fmt ( f) ,
181+ TableConstraint :: Exclude ( constraint) => constraint. fmt ( f) ,
182182 }
183183 }
184184}
@@ -617,22 +617,24 @@ impl crate::ast::Spanned for ConstraintUsingIndex {
617617 }
618618}
619619
620- /// The operator that follows `WITH` in an `EXCLUDE` element.
620+ /// The operator that follows `WITH` in an `EXCLUDE` constraint element.
621+ ///
622+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE)
621623#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
622624#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
623625#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
624- pub enum ExclusionOperator {
626+ pub enum ExcludeConstraintOperator {
625627 /// A single operator token, e.g. `=`, `&&`, `<->`.
626628 Token ( String ) ,
627629 /// Postgres schema-qualified form: `OPERATOR(schema.op)`.
628630 PgCustom ( Vec < String > ) ,
629631}
630632
631- impl fmt:: Display for ExclusionOperator {
633+ impl fmt:: Display for ExcludeConstraintOperator {
632634 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
633635 match self {
634- ExclusionOperator :: Token ( token) => f. write_str ( token) ,
635- ExclusionOperator :: PgCustom ( parts) => {
636+ ExcludeConstraintOperator :: Token ( token) => f. write_str ( token) ,
637+ ExcludeConstraintOperator :: PgCustom ( parts) => {
636638 write ! ( f, "OPERATOR({})" , display_separated( parts, "." ) )
637639 }
638640 }
@@ -641,58 +643,46 @@ impl fmt::Display for ExclusionOperator {
641643
642644/// One element in an `EXCLUDE` constraint's element list.
643645///
644- /// `{ column_name | ( expression ) } [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] WITH <operator>`
645- ///
646- /// See <https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE>
646+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE)
647647#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
648648#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
649649#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
650- pub struct ExclusionElement {
651- /// The index expression or column name.
652- pub expr : Expr ,
653- /// Optional operator class (e.g. `gist_geometry_ops_nd`).
654- pub operator_class : Option < ObjectName > ,
655- /// Ordering options (ASC/DESC, NULLS FIRST/LAST).
656- pub order : OrderByOptions ,
650+ pub struct ExcludeConstraintElement {
651+ /// The index column (`{ column_name | ( expression ) } [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]`).
652+ pub column : IndexColumn ,
657653 /// The exclusion operator.
658- pub operator : ExclusionOperator ,
654+ pub operator : ExcludeConstraintOperator ,
659655}
660656
661- impl fmt:: Display for ExclusionElement {
657+ impl fmt:: Display for ExcludeConstraintElement {
662658 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
663- write ! ( f, "{}" , self . expr) ?;
664- if let Some ( opclass) = & self . operator_class {
665- write ! ( f, " {opclass}" ) ?;
666- }
667- write ! ( f, "{} WITH {}" , self . order, self . operator)
659+ write ! ( f, "{} WITH {}" , self . column, self . operator)
668660 }
669661}
670662
671- impl crate :: ast:: Spanned for ExclusionElement {
663+ impl crate :: ast:: Spanned for ExcludeConstraintElement {
672664 fn span ( & self ) -> Span {
673- let mut span = self . expr . span ( ) ;
674- if let Some ( opclass) = & self . operator_class {
665+ let mut span = self . column . column . expr . span ( ) ;
666+ if let Some ( opclass) = & self . column . operator_class {
675667 span = span. union ( & opclass. span ( ) ) ;
676668 }
677669 span
678670 }
679671}
680672
681- /// A PostgreSQL `EXCLUDE` constraint.
682- ///
683- /// `[ CONSTRAINT <name> ] EXCLUDE [ USING <index_method> ] ( <element> WITH <operator> [, ...] ) [ INCLUDE (<cols>) ] [ WHERE (<predicate>) ]`
673+ /// An `EXCLUDE` constraint.
684674///
685- /// See < https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE>
675+ /// [PostgreSql]( https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE)
686676#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
687677#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
688678#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
689- pub struct ExclusionConstraint {
679+ pub struct ExcludeConstraint {
690680 /// Optional constraint name.
691681 pub name : Option < Ident > ,
692682 /// Optional index method (e.g. `gist`, `spgist`).
693683 pub index_method : Option < Ident > ,
694684 /// The list of index expressions with their exclusion operators.
695- pub elements : Vec < ExclusionElement > ,
685+ pub elements : Vec < ExcludeConstraintElement > ,
696686 /// Optional list of additional columns to include in the index.
697687 pub include : Vec < Ident > ,
698688 /// Optional `WHERE` predicate to restrict the constraint to a subset of rows.
@@ -701,7 +691,7 @@ pub struct ExclusionConstraint {
701691 pub characteristics : Option < ConstraintCharacteristics > ,
702692}
703693
704- impl fmt:: Display for ExclusionConstraint {
694+ impl fmt:: Display for ExcludeConstraint {
705695 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
706696 use crate :: ast:: ddl:: display_constraint_name;
707697 write ! ( f, "{}EXCLUDE" , display_constraint_name( & self . name) ) ?;
@@ -722,7 +712,7 @@ impl fmt::Display for ExclusionConstraint {
722712 }
723713}
724714
725- impl crate :: ast:: Spanned for ExclusionConstraint {
715+ impl crate :: ast:: Spanned for ExcludeConstraint {
726716 fn span ( & self ) -> Span {
727717 Span :: union_iter (
728718 self . name
0 commit comments