@@ -7940,7 +7940,7 @@ impl<'a> Parser<'a> {
79407940 }
79417941
79427942 pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
7943- let name = self.parse_identifier()?;
7943+ let col_name = self.parse_identifier()?;
79447944 let data_type = if self.is_column_type_sqlite_unspecified() {
79457945 DataType::Unspecified
79467946 } else {
@@ -7965,7 +7965,7 @@ impl<'a> Parser<'a> {
79657965 };
79667966 }
79677967 Ok(ColumnDef {
7968- name,
7968+ name: col_name ,
79697969 data_type,
79707970 options,
79717971 })
@@ -8065,10 +8065,15 @@ impl<'a> Parser<'a> {
80658065 // PostgreSQL allows omitting the column list and
80668066 // uses the primary key column of the foreign table by default
80678067 let referred_columns = self.parse_parenthesized_column_list(Optional, false)?;
8068+ let mut match_kind = None;
80688069 let mut on_delete = None;
80698070 let mut on_update = None;
80708071 loop {
8071- if on_delete.is_none() && self.parse_keywords(&[Keyword::ON, Keyword::DELETE]) {
8072+ if match_kind.is_none() && self.parse_keyword(Keyword::MATCH) {
8073+ match_kind = Some(self.parse_match_kind()?);
8074+ } else if on_delete.is_none()
8075+ && self.parse_keywords(&[Keyword::ON, Keyword::DELETE])
8076+ {
80728077 on_delete = Some(self.parse_referential_action()?);
80738078 } else if on_update.is_none()
80748079 && self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
@@ -8080,13 +8085,20 @@ impl<'a> Parser<'a> {
80808085 }
80818086 let characteristics = self.parse_constraint_characteristics()?;
80828087
8083- Ok(Some(ColumnOption::ForeignKey {
8084- foreign_table,
8085- referred_columns,
8086- on_delete,
8087- on_update,
8088- characteristics,
8089- }))
8088+ Ok(Some(
8089+ ForeignKeyConstraint {
8090+ name: None, // Column-level constraints don't have names
8091+ index_name: None, // Not applicable for column-level constraints
8092+ columns: vec![], // Not applicable for column-level constraints
8093+ foreign_table,
8094+ referred_columns,
8095+ on_delete,
8096+ on_update,
8097+ match_kind,
8098+ characteristics,
8099+ }
8100+ .into(),
8101+ ))
80908102 } else if self.parse_keyword(Keyword::CHECK) {
80918103 self.expect_token(&Token::LParen)?;
80928104 // since `CHECK` requires parentheses, we can parse the inner expression in ParserState::Normal
@@ -8367,6 +8379,18 @@ impl<'a> Parser<'a> {
83678379 }
83688380 }
83698381
8382+ pub fn parse_match_kind(&mut self) -> Result<ConstraintReferenceMatchKind, ParserError> {
8383+ if self.parse_keyword(Keyword::FULL) {
8384+ Ok(ConstraintReferenceMatchKind::Full)
8385+ } else if self.parse_keyword(Keyword::PARTIAL) {
8386+ Ok(ConstraintReferenceMatchKind::Partial)
8387+ } else if self.parse_keyword(Keyword::SIMPLE) {
8388+ Ok(ConstraintReferenceMatchKind::Simple)
8389+ } else {
8390+ self.expected("one of FULL, PARTIAL or SIMPLE", self.peek_token())
8391+ }
8392+ }
8393+
83708394 pub fn parse_constraint_characteristics(
83718395 &mut self,
83728396 ) -> Result<Option<ConstraintCharacteristics>, ParserError> {
@@ -8477,10 +8501,15 @@ impl<'a> Parser<'a> {
84778501 self.expect_keyword_is(Keyword::REFERENCES)?;
84788502 let foreign_table = self.parse_object_name(false)?;
84798503 let referred_columns = self.parse_parenthesized_column_list(Optional, false)?;
8504+ let mut match_kind = None;
84808505 let mut on_delete = None;
84818506 let mut on_update = None;
84828507 loop {
8483- if on_delete.is_none() && self.parse_keywords(&[Keyword::ON, Keyword::DELETE]) {
8508+ if match_kind.is_none() && self.parse_keyword(Keyword::MATCH) {
8509+ match_kind = Some(self.parse_match_kind()?);
8510+ } else if on_delete.is_none()
8511+ && self.parse_keywords(&[Keyword::ON, Keyword::DELETE])
8512+ {
84848513 on_delete = Some(self.parse_referential_action()?);
84858514 } else if on_update.is_none()
84868515 && self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
@@ -8502,6 +8531,7 @@ impl<'a> Parser<'a> {
85028531 referred_columns,
85038532 on_delete,
85048533 on_update,
8534+ match_kind,
85058535 characteristics,
85068536 }
85078537 .into(),
0 commit comments