Skip to content

Commit c776f9b

Browse files
committed
support NUMBER(10, 0) type
1 parent 7afa7fe commit c776f9b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

mindsdb_sql_parser/ast/create.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010

1111
class TableColumn():
12-
def __init__(self, name, type='integer', length=None, default=None,
12+
def __init__(self, name, type='integer', length=None, length2=None, default=None,
1313
is_primary_key=False, nullable=None):
1414
self.name = name
1515
self.type = type
1616
self.is_primary_key = is_primary_key
1717
self.default = default
1818
self.length = length
19+
self.length2 = length2
1920
self.nullable = nullable
2021

2122
def __eq__(self, other):
@@ -97,7 +98,10 @@ def get_string(self, *args, **kwargs):
9798
else:
9899
type = str(col.type)
99100
if col.length is not None:
100-
type = f'{type}({col.length})'
101+
len_str = str(col.length)
102+
if col.length2 is not None:
103+
len_str += f", {col.length2}"
104+
type = f'{type}({len_str})'
101105
col_str = f'{col.name} {type}'
102106
if col.nullable is True:
103107
col_str += ' NULL'

mindsdb_sql_parser/parser.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ def drop_table(self, p):
713713
'id id DEFAULT id',
714714
'id id PRIMARY_KEY',
715715
'id id LPAREN INTEGER RPAREN',
716+
'id id LPAREN INTEGER COMMA INTEGER RPAREN',
716717
'id id LPAREN INTEGER RPAREN DEFAULT id',
717718
'PRIMARY_KEY LPAREN column_list RPAREN',
718719
)
@@ -730,10 +731,18 @@ def table_column(self, p):
730731
elif hasattr(p, 'PRIMARY_KEY'):
731732
is_primary_key = True
732733

734+
length, length2 = None, None
735+
if hasattr(p, 'INTEGER'):
736+
length = p.INTEGER
737+
elif hasattr(p, 'INTEGER0'):
738+
length = p.INTEGER0
739+
length2 = p.INTEGER1
740+
733741
return TableColumn(
734742
name=p[0],
735743
type=p[1],
736-
length=getattr(p, 'INTEGER', None),
744+
length=length,
745+
length2=length2,
737746
default=default,
738747
is_primary_key=is_primary_key
739748
)

tests/test_base_sql/test_create.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def test_create(self):
137137
location_id INT,
138138
num INT,
139139
name TEXT,
140+
balance decimal(5,2),
141+
links NUMBER(10, 0) NOT NULL,
140142
PRIMARY KEY (location_id, num)
141143
)
142144
'''
@@ -148,6 +150,8 @@ def test_create(self):
148150
TableColumn(name='location_id', type='INT', is_primary_key=True),
149151
TableColumn(name='num', type='INT', is_primary_key=True),
150152
TableColumn(name='name', type='TEXT'),
153+
TableColumn(name='balance', type='decimal', length=5, length2=2),
154+
TableColumn(name='links', type='NUMBER', nullable=False, length=10, length2=0),
151155
]
152156
)
153157

0 commit comments

Comments
 (0)