Skip to content

Commit

Permalink
fix: Alter table with unique constraint with postgres syntaxe work an…
Browse files Browse the repository at this point in the history
…d keep the

previous mariadb syntax.
  • Loading branch information
antoineB committed Oct 15, 2023
1 parent 385aff4 commit 23cca53
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
15 changes: 11 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2309,13 +2309,20 @@ module.exports = grammar({
),

_key_constraint: $ => seq(
optional(
choice(
choice(
seq(
$.keyword_unique,
$.keyword_foreign,
optional(
choice(
$.keyword_index,
$.keyword_key,
seq($.keyword_nulls, optional($.keyword_not), $.keyword_distinct),
),
),
),
seq(optional($.keyword_foreign), $.keyword_key, optional($._if_not_exists)),
$.keyword_index,
),
choice($.keyword_key, $.keyword_index),
optional(field('name', $.identifier)),
paren_list($.identifier, true),
optional(
Expand Down
26 changes: 26 additions & 0 deletions test/corpus/alter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1165,3 +1165,29 @@ ON UPDATE SET DEFAULT;
(keyword_update)
(keyword_set)
(keyword_default))))))

================================================================================
Add unique constraint
================================================================================

ALTER TABLE table_name
ADD CONSTRAINT constraint_name UNIQUE (col1, col2, col3);

--------------------------------------------------------------------------------

(program
(statement
(alter_table
(keyword_alter)
(keyword_table)
(object_reference
(identifier))
(add_constraint
(keyword_add)
(keyword_constraint)
(identifier)
(constraint
(keyword_unique)
(identifier)
(identifier)
(identifier))))))

0 comments on commit 23cca53

Please sign in to comment.