Skip to content

Commit 9a8b1e0

Browse files
authored
Fix handling of the ALTER TABLE ... ADD KEY queries (#553)
* Add the test_alter suite (see #542) * RELEVANT_KEYWORDS: treat the KEY token in the same way as INDEX is treated
1 parent 8df3ffc commit 9a8b1e0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sql_metadata/keywords_lists.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class TokenType(str, Enum):
125125
"RETURNING",
126126
"VALUES",
127127
"INDEX",
128+
"KEY",
128129
"WITH",
129130
"WINDOW",
130131
}

test/test_alter.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from sql_metadata import Parser, QueryType
2+
3+
4+
def test_alter_table_indices_key():
5+
parser = Parser("ALTER TABLE foo_table ADD KEY `idx_foo` (`bar`);")
6+
assert parser.query_type == QueryType.ALTER
7+
assert parser.tables == ["foo_table"]
8+
9+
10+
def test_alter_table_indices_index():
11+
parser = Parser("ALTER TABLE foo_table ADD INDEX `idx_foo` (`bar`);")
12+
assert parser.query_type == QueryType.ALTER
13+
assert parser.tables == ["foo_table"]

0 commit comments

Comments
 (0)