Skip to content
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

[MariaDB] Use ifNotExists clause correctly for unique key constraint #4250

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions sql/mariadb/MariaDBParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,7 @@ alterSpecification
| ADD indexFormat = (INDEX | KEY) ifNotExists? uid? indexType? // here ifNotExists is MariaDB-specific only
indexColumnNames indexOption* # alterByAddIndex
| ADD (CONSTRAINT name = uid?)? PRIMARY KEY index = uid? indexType? indexColumnNames indexOption* # alterByAddPrimaryKey
| ADD (CONSTRAINT name = uid?)? UNIQUE ifNotExists? indexFormat = (INDEX | KEY)? indexName = uid? indexType? indexColumnNames indexOption* #
alterByAddUniqueKey
| ADD (CONSTRAINT name = uid?)? UNIQUE indexFormat = (INDEX | KEY)? ifNotExists? indexName = uid? indexType? indexColumnNames indexOption* #alterByAddUniqueKey
| ADD keyType = (FULLTEXT | SPATIAL) indexFormat = (INDEX | KEY)? uid? indexColumnNames indexOption* # alterByAddSpecialIndex
| ADD (CONSTRAINT name = uid?)? FOREIGN KEY ifNotExists? // here ifNotExists is MariaDB-specific only
indexName = uid? indexColumnNames referenceDefinition # alterByAddForeignKey
Expand Down
5 changes: 5 additions & 0 deletions sql/mariadb/examples/fast/ddl_alter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ rename user user1@100.200.1.1 to user2@2001:0db8:85a3:0000:0000:8a2e:0370:7334;
#end
ALTER TABLE t1 ADD PARTITION (PARTITION p3 VALUES LESS THAN (2002));
ALTER TABLE t1 ADD PARTITION IF NOT EXISTS (PARTITION p3 VALUES LESS THAN (2002));
ALTER TABLE my_table
ADD CONSTRAINT my_table_to_dealers_fk
FOREIGN KEY IF NOT EXISTS (dealer_id) REFERENCES n_dealers (id),
ADD CONSTRAINT my_table_trigger_ranking_class_version_dealer_uk UNIQUE KEY IF NOT EXISTS (trigger_id, ranking_criteria, classification_id, version, dealer_id),
ADD CONSTRAINT trigger_classification_to_trigger_name_fk FOREIGN KEY IF NOT EXISTS (trigger_id) REFERENCES n_vulnerability_triggers (id);
-- Alter sequence
ALTER SEQUENCE IF EXISTS s2 start=100;
ALTER SEQUENCE s1 CACHE=1000 NOCYCLE RESTART WITH 1;
Expand Down
Loading