Skip to content

Allow foreign table constraint without columns #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6830,7 +6830,15 @@ impl<'a> Parser<'a> {
let columns = self.parse_parenthesized_column_list(Mandatory, false)?;
self.expect_keyword(Keyword::REFERENCES)?;
let foreign_table = self.parse_object_name(false)?;
let referred_columns = self.parse_parenthesized_column_list(Mandatory, false)?;
// PostgreSQL allows foreign key columns to be optional
// (https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-REFERENCES)
let parenthesized_column_list_optional = if dialect_of!(self is PostgreSqlDialect) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this behavior is a superset of the previous I think we can do without the dialect check and always set to Optional?

Also could we add a test case to sqlparse_common.rs demonstrating the new behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Made the change.

Optional
} else {
Mandatory
};
let referred_columns = self
.parse_parenthesized_column_list(parenthesized_column_list_optional, false)?;
let mut on_delete = None;
let mut on_update = None;
loop {
Expand Down