[#7268] Add support for MySQL's UNIQUE [ index_name ] syntax

This commit is contained in:
lukaseder 2018-12-11 16:30:49 +01:00
parent 928175ed41
commit b06cd5f5d0
2 changed files with 7 additions and 1 deletions

View File

@ -307,7 +307,7 @@ index = ( 'KEY' | 'INDEX' ) [ identifier ] '(' sortFields ')'
constraint =
(
'PRIMARY KEY' '(' fieldNames ')'
| 'UNIQUE' [ 'KEY' | 'INDEX' ] '(' fieldNames ')'
| 'UNIQUE' [ 'KEY' | 'INDEX' ] [ identifier ] '(' sortFields ')'
| 'FOREIGN KEY' '(' fieldNames ')' 'REFERENCES' constraintReferenceSpecification
| 'CHECK' '(' condition ')'
) [ 'ENABLE' ]

View File

@ -2452,6 +2452,12 @@ final class ParserImpl implements Parser {
if (!parseKeywordIf(ctx, "KEY"))
parseKeywordIf(ctx, "INDEX");
// [#7268] MySQL has some legacy syntax where an index name
// can override a constraint name
Name index = parseIdentifierIf(ctx);
if (index != null)
constraint = constraint(index);
constraints.add(parseUniqueSpecification(ctx, constraint));
continue columnLoop;
}