@@ -669,6 +669,8 @@ pub enum TableConstraint {
669669 columns : Vec < Ident > ,
670670 index_options : Vec < IndexOption > ,
671671 characteristics : Option < ConstraintCharacteristics > ,
672+ /// Optional Postgres nulls handling: `[ NULLS [ NOT ] DISTINCT ]`
673+ nulls_distinct : NullsDistinctOption ,
672674 } ,
673675 /// MySQL [definition][1] for `PRIMARY KEY` constraints statements:\
674676 /// * `[CONSTRAINT [<name>]] PRIMARY KEY [index_name] [index_type] (<columns>) <index_options>`
@@ -777,10 +779,11 @@ impl fmt::Display for TableConstraint {
777779 columns,
778780 index_options,
779781 characteristics,
782+ nulls_distinct,
780783 } => {
781784 write ! (
782785 f,
783- "{}UNIQUE{index_type_display:>}{}{} ({})" ,
786+ "{}UNIQUE{nulls_distinct}{ index_type_display:>}{}{} ({})" ,
784787 display_constraint_name( name) ,
785788 display_option_spaced( index_name) ,
786789 display_option( " USING " , "" , index_type) ,
@@ -988,6 +991,31 @@ impl fmt::Display for IndexOption {
988991 }
989992}
990993
994+ /// [Postgres] unique index nulls handling option: `[ NULLS [ NOT ] DISTINCT ]`
995+ ///
996+ /// [Postgres]: https://www.postgresql.org/docs/17/sql-altertable.html
997+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
998+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
999+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1000+ pub enum NullsDistinctOption {
1001+ /// Not specified
1002+ None ,
1003+ /// NULLS DISTINCT
1004+ Distinct ,
1005+ /// NULLS NOT DISTINCT
1006+ NotDistinct ,
1007+ }
1008+
1009+ impl fmt:: Display for NullsDistinctOption {
1010+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1011+ match self {
1012+ Self :: None => Ok ( ( ) ) ,
1013+ Self :: Distinct => write ! ( f, " NULLS DISTINCT" ) ,
1014+ Self :: NotDistinct => write ! ( f, " NULLS NOT DISTINCT" ) ,
1015+ }
1016+ }
1017+ }
1018+
9911019#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9921020#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9931021#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
0 commit comments