@@ -31,17 +31,17 @@ use sqlparser_derive::{Visit, VisitMut};
3131use crate :: ast:: helpers:: attached_token:: AttachedToken ;
3232use crate :: ast:: table_constraints:: TableConstraint ;
3333use crate :: ast:: value:: escape_single_quote_string;
34+ use crate :: ast:: { CreateViewParams , FunctionDesc , HiveSetLocation } ;
3435use crate :: ast:: {
35- display_comma_separated, display_separated, ArgMode , CommentDef , ConditionalStatements ,
36- CreateFunctionBody , CreateFunctionUsing , CreateTableLikeKind , CreateTableOptions ,
37- CreateViewParams , DataType , Expr , FileFormat , FunctionBehavior , FunctionCalledOnNull ,
38- FunctionDesc , FunctionDeterminismSpecifier , FunctionParallel , HiveDistributionStyle ,
39- HiveFormat , HiveIOFormat , HiveRowFormat , HiveSetLocation , Ident , InitializeKind ,
40- MySQLColumnPosition , ObjectName , OnCommit , OneOrManyWithParens , OperateFunctionArg ,
41- OrderByExpr , ProjectionSelect , Query , RefreshModeKind , RowAccessPolicy , SequenceOptions ,
42- Spanned , SqlOption , StorageSerializationPolicy , TableVersion , Tag , TriggerEvent ,
43- TriggerExecBody , TriggerObject , TriggerPeriod , TriggerReferencing , Value , ValueWithSpan ,
44- WrappedCollection ,
36+ display_comma_separated, display_separated, table_constraints:: ForeignKeyConstraint , ArgMode ,
37+ CommentDef , ConditionalStatements , CreateFunctionBody , CreateFunctionUsing ,
38+ CreateTableLikeKind , CreateTableOptions , DataType , Expr , FileFormat , FunctionBehavior ,
39+ FunctionCalledOnNull , FunctionDeterminismSpecifier , FunctionParallel , HiveDistributionStyle ,
40+ HiveFormat , HiveIOFormat , HiveRowFormat , Ident , InitializeKind , MySQLColumnPosition ,
41+ ObjectName , OnCommit , OneOrManyWithParens , OperateFunctionArg , OrderByExpr , ProjectionSelect ,
42+ Query , RefreshModeKind , RowAccessPolicy , SequenceOptions , Spanned , SqlOption ,
43+ StorageSerializationPolicy , TableVersion , Tag , TriggerEvent , TriggerExecBody , TriggerObject ,
44+ TriggerPeriod , TriggerReferencing , Value , ValueWithSpan , WrappedCollection ,
4545} ;
4646use crate :: display_utils:: { DisplayCommaSeparated , Indent , NewLine , SpaceOrNewline } ;
4747use crate :: keywords:: Keyword ;
@@ -1176,12 +1176,19 @@ pub struct ProcedureParam {
11761176 pub name : Ident ,
11771177 pub data_type : DataType ,
11781178 pub mode : Option < ArgMode > ,
1179+ pub default : Option < Expr > ,
11791180}
11801181
11811182impl fmt:: Display for ProcedureParam {
11821183 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
11831184 if let Some ( mode) = & self . mode {
1184- write ! ( f, "{mode} {} {}" , self . name, self . data_type)
1185+ if let Some ( default) = & self . default {
1186+ write ! ( f, "{mode} {} {} = {}" , self . name, self . data_type, default )
1187+ } else {
1188+ write ! ( f, "{mode} {} {}" , self . name, self . data_type)
1189+ }
1190+ } else if let Some ( default) = & self . default {
1191+ write ! ( f, "{} {} = {}" , self . name, self . data_type, default )
11851192 } else {
11861193 write ! ( f, "{} {}" , self . name, self . data_type)
11871194 }
@@ -1554,20 +1561,14 @@ pub enum ColumnOption {
15541561 is_primary : bool ,
15551562 characteristics : Option < ConstraintCharacteristics > ,
15561563 } ,
1557- /// A referential integrity constraint (`[FOREIGN KEY REFERENCES
1558- /// <foreign_table> (<referred_columns>)
1564+ /// A referential integrity constraint (`REFERENCES <foreign_table> (<referred_columns>)
1565+ /// [ MATCH { FULL | PARTIAL | SIMPLE } ]
15591566 /// { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] |
15601567 /// [ON UPDATE <referential_action>] [ON DELETE <referential_action>]
1561- /// }
1568+ /// }
15621569 /// [<constraint_characteristics>]
15631570 /// `).
1564- ForeignKey {
1565- foreign_table : ObjectName ,
1566- referred_columns : Vec < Ident > ,
1567- on_delete : Option < ReferentialAction > ,
1568- on_update : Option < ReferentialAction > ,
1569- characteristics : Option < ConstraintCharacteristics > ,
1570- } ,
1571+ ForeignKey ( ForeignKeyConstraint ) ,
15711572 /// `CHECK (<expr>)`
15721573 Check ( Expr ) ,
15731574 /// Dialect-specific options, such as:
@@ -1638,6 +1639,12 @@ pub enum ColumnOption {
16381639 Invisible ,
16391640}
16401641
1642+ impl From < ForeignKeyConstraint > for ColumnOption {
1643+ fn from ( fk : ForeignKeyConstraint ) -> Self {
1644+ ColumnOption :: ForeignKey ( fk)
1645+ }
1646+ }
1647+
16411648impl fmt:: Display for ColumnOption {
16421649 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
16431650 use ColumnOption :: * ;
@@ -1664,24 +1671,25 @@ impl fmt::Display for ColumnOption {
16641671 }
16651672 Ok ( ( ) )
16661673 }
1667- ForeignKey {
1668- foreign_table,
1669- referred_columns,
1670- on_delete,
1671- on_update,
1672- characteristics,
1673- } => {
1674- write ! ( f, "REFERENCES {foreign_table}" ) ?;
1675- if !referred_columns. is_empty ( ) {
1676- write ! ( f, " ({})" , display_comma_separated( referred_columns) ) ?;
1674+ ForeignKey ( constraint) => {
1675+ write ! ( f, "REFERENCES {}" , constraint. foreign_table) ?;
1676+ if !constraint. referred_columns . is_empty ( ) {
1677+ write ! (
1678+ f,
1679+ " ({})" ,
1680+ display_comma_separated( & constraint. referred_columns)
1681+ ) ?;
1682+ }
1683+ if let Some ( match_kind) = & constraint. match_kind {
1684+ write ! ( f, " {match_kind}" ) ?;
16771685 }
1678- if let Some ( action) = on_delete {
1686+ if let Some ( action) = & constraint . on_delete {
16791687 write ! ( f, " ON DELETE {action}" ) ?;
16801688 }
1681- if let Some ( action) = on_update {
1689+ if let Some ( action) = & constraint . on_update {
16821690 write ! ( f, " ON UPDATE {action}" ) ?;
16831691 }
1684- if let Some ( characteristics) = characteristics {
1692+ if let Some ( characteristics) = & constraint . characteristics {
16851693 write ! ( f, " {characteristics}" ) ?;
16861694 }
16871695 Ok ( ( ) )
0 commit comments