-
Notifications
You must be signed in to change notification settings - Fork 534
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
Support MySQL UNIQUE
table constraint
#1164
Conversation
Also * use different names for constraint name and index name. In MySQL they can be obtained by `SELECT index_name FROM INFORMATION_SCHEMA.STATISTICS` and `SELECT constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS`. But in MySQL `CONSTRAINT `a` UNIQUE `b` (x)` will set `b` and for `index_name` and for `constraint_name` so I don't sure it's it really needed to split them or not. * Allow use `INDEX` after `UNIQUE` Currently allowed index options: * `USING {HASH | BTREE}` * `COMMENT 'string'`
As it said `INDEX ind (foo)` form of constraint was found only in MySQL, but in MySQL allowed only `INDEX ind (foo)` without `CONSTRAINT bar` so if there was `name` then unallow `INDEX` constraint.
Pull Request Test Coverage Report for Build 8621622983Details
💛 - Coveralls |
Yes, I agree this would make more sense than trying to combine UNIQUE and PRIMARY KEY syntaxes together Are you willing to make this change? I am really sorry for the delay in reviewing |
I do the split, but now I'm unsure that it was good idea, because MySql specification say that there no Their similarity is visible in tests during creation and during assertion of inner structure. But still maybe when they are separate it's more expected by an user, idk. |
Also during last changes I add some functions like For example instead next if let Some(exclude) = &self.opt_exclude {
write!(f, " {exclude}")?;
}
if let Some(except) = &self.opt_except {
write!(f, " {except}")?;
}
if let Some(rename) = &self.opt_rename {
write!(f, " {rename}")?;
}
if let Some(replace) = &self.opt_replace {
write!(f, " {replace}")?;
} you can write write!(
f,
"{}{}{}{}",
display_option_spaced(&self.opt_exclude),
display_option_spaced(&self.opt_except),
display_option_spaced(&self.opt_rename),
display_option_spaced(&self.opt_replace),
)?; I think it will be pretty convenient for fmt |
I agree -- the sqlparser's crate aim is to preserve syntax and it is up downstream consumers to decide how to handle the semantics (e.g if they want to treat |
UNIQUE
table constraint fixUNIQUE
table constraint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @Nikita-str -- I pushed a few small comment improvements and then I'll merge this PR in.
Thanks again and sorry for the delay in reviewing
@@ -922,6 +1037,36 @@ fn display_constraint_name(name: &'_ Option<Ident>) -> impl fmt::Display + '_ { | |||
ConstraintName(name) | |||
} | |||
|
|||
/// If `option` is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I agree this is very nice
Thanks again @Nikita-str |
Co-authored-by: Andrew Lamb <[email protected]>
Fix to #1149 and some more.
Allow to parse
[CONSTRAINT [name]] UNIQUE [INDEX | KEY] [index_name] [index_type] (<columns>) [index_option]s ...
as it say in the specification.Also unallow
CONSTRAINT bar INDEX ind (foo)
for table constraint; as it was saidINDEX ind (foo)
form of table constraint was found only in MySQL, but in MySQL allowed onlyINDEX ind (foo)
withoutCONSTRAINT bar
before it.Some remarks:
TableConstraint::Unique
intoTableConstraint::Unique
&TableConstraint::Primary
?IndexOption
struct, and maybe it can be unite with some another structure, I unsure.CONSTRAINT a UNIQUE b (x)
will setb
and forindex_name
(in MySQL you can obtain it bySELECT index_name FROM INFORMATION_SCHEMA.STATISTICS
) and forconstraint_name
(in MySQL you can obtain it bySELECT constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
) so I don't sure if names really needed to be splitted.