Skip to content

Conversation

LucaCappelletti94
Copy link
Contributor

This PR adds support for the SQL standard MATCH [FULL | PARTIAL | SIMPLE] syntax for foreign key constraints.

Changes

  • Extended keywords to include PARTIAL and SIMPLE
  • New MatchKind enum with Full, Partial, and Simple variants
  • Parser support for MATCH syntax in both column-level and table-level foreign key constraints
  • Refactored ColumnOption::ForeignKey to use ForeignKeyConstraint struct, eliminating code duplication
  • Added opportune tests
  • Added opportune documentation for newly supported syntax

Examples

-- Column-level constraint
CREATE TABLE orders (
    id INT REFERENCES customers(id) MATCH FULL ON DELETE CASCADE
);

-- Table-level constraint  
CREATE TABLE orders (
    customer_id INT,
    FOREIGN KEY (customer_id) REFERENCES customers(id) MATCH SIMPLE
);

Closes issue #2061 and works towards closing issue #2059

if self.parse_keyword(Keyword::CONSTRAINT) {
let name = Some(self.parse_identifier()?);
if let Some(option) = self.parse_optional_column_option()? {
if let Some(option) = self.parse_optional_column_option(&col_name)? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what this change implies, it looks like we'd be storing the column name twice in the AST node which doesn't seem ideal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed to standardize ForeignKeyConstraint and avoid having a duplicated struct to represent the same type of concept. I could possibly leave the columns vector of the ForeignKeyConstraint empty, but when I use that struct in code that works on top of the AST it is quite useful to have the column ident defined there, and not have to handle the case of a special ForeignKeyConstraint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will note that it is the same change needed for PR #2064, which I did separately but the goal is identical - to standardize the structs used to represent constraints in the columns and table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants