Skip to content

Commit 320fd72

Browse files
moved the FROM clause before query
1 parent ed7bb2c commit 320fd72

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

mindsdb_sql_parser/ast/mindsdb/alter_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def to_tree(self, *args, level=0, **kwargs):
4242
return out_str
4343

4444
def get_string(self, *args, **kwargs):
45-
from_str = f' FROM {str(self.from_table)} ' if self.from_table else ''
45+
from_str = f' FROM {str(self.from_table)}' if self.from_table else ''
4646

47-
out_str = f'ALTER VIEW {self.name.to_string()} AS ( {self.query_str} ){from_str}'
47+
out_str = f'ALTER VIEW {self.name.to_string()}{from_str} AS ( {self.query_str} )'
4848

4949
return out_str

mindsdb_sql_parser/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,8 @@ def create_view(self, p):
693693
if_not_exists=p.if_not_exists_or_empty)
694694

695695
# ALTER VIEW
696-
@_('ALTER VIEW identifier AS LPAREN raw_query RPAREN create_view_from_table_or_nothing',
697-
'ALTER VIEW identifier LPAREN raw_query RPAREN create_view_from_table_or_nothing')
696+
@_('ALTER VIEW identifier create_view_from_table_or_nothing AS LPAREN raw_query RPAREN',
697+
'ALTER VIEW identifier create_view_from_table_or_nothing LPAREN raw_query RPAREN')
698698
def alter_view(self, p):
699699
query_str = tokens_to_string(p.raw_query)
700700

tests/test_mindsdb/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_create_view_nofrom(self):
3535
assert ast.to_tree() == expected_ast.to_tree()
3636

3737
def test_alter_view_full(self):
38-
sql = "ALTER VIEW my_view AS ( SELECT * FROM pred ) FROM integr"
38+
sql = "ALTER VIEW my_view FROM integr AS ( SELECT * FROM pred )"
3939
ast = parse_sql(sql)
4040
expected_ast = AlterView(
4141
name=Identifier('my_view'),

0 commit comments

Comments
 (0)