Skip to content

Commit 8bc502b

Browse files
authored
Merge pull request #30 from mindsdb/primary-varchar
Support length in primary key type
2 parents 75420c6 + f8a1929 commit 8bc502b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

mindsdb_sql_parser/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ def drop_table(self, p):
723723
@_('id id',
724724
'id id DEFAULT id',
725725
'id id PRIMARY_KEY',
726+
'id id LPAREN INTEGER RPAREN PRIMARY_KEY',
726727
'id id LPAREN INTEGER RPAREN',
727728
'id id LPAREN INTEGER COMMA INTEGER RPAREN',
728729
'id id LPAREN INTEGER RPAREN DEFAULT id',

tests/test_base_sql/test_create.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ def test_create(self):
130130
assert str(ast).lower() == str(expected_ast).lower()
131131
assert ast.to_tree() == expected_ast.to_tree()
132132

133+
sql = f'''
134+
CREATE TABLE mydb.Persons(
135+
Person varchar(10) PRIMARY KEY not null,
136+
name TEXT NULL
137+
)
138+
'''
139+
ast = parse_sql(sql)
140+
141+
expected_ast = CreateTable(
142+
name=Identifier('mydb.Persons'),
143+
columns=[
144+
TableColumn(name='Person', type='varchar', length=10, is_primary_key=True, nullable=False),
145+
TableColumn(name='name', type='TEXT', nullable=True),
146+
]
147+
)
148+
149+
assert str(ast).lower() == str(expected_ast).lower()
150+
assert ast.to_tree() == expected_ast.to_tree()
151+
152+
133153
# multiple primary keys
134154

135155
sql = f'''

0 commit comments

Comments
 (0)