Skip to content

Commit

Permalink
interval format is
Browse files Browse the repository at this point in the history
INTERVAL '1' day
  • Loading branch information
ea-rus committed Aug 30, 2024
1 parent 7bc726a commit 16ee899
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mindsdb_sql/parser/ast/select/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __init__(self, info):
super().__init__(op='interval', args=[info, ])

def get_string(self, *args, **kwargs):
return f'INTERVAL {repr(self.args[0])}'
return f'INTERVAL {self.args[0]}'

def to_tree(self, *args, level=0, **kwargs):
return self.get_string( *args, **kwargs)
Expand Down
5 changes: 4 additions & 1 deletion mindsdb_sql/render/sqlalchemy_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def __init__(self, info):

@compiles(INTERVAL)
def _compile_interval(element, compiler, **kw):
return f"INTERVAL '{element.info}'"
items = element.info.split(' ', maxsplit=1)
# quote first element
items[0] = f"'{items[0]}'"
return "INTERVAL " + " ".join(items)


class SqlalchemyRender:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser/test_base_sql/test_misc_sql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_interval(self):
for value in ('1 day', "'1' day", "'1 day'"):
sql = f"""
select interval {value} + 1 from aaa
where 'a' > interval "3 day 1 min"
where 'a' > interval "1 min"
"""

expected_ast = Select(
Expand All @@ -250,7 +250,7 @@ def test_interval(self):
op='>',
args=[
Constant('a'),
Interval('3 day 1 min'),
Interval('1 min'),
]
)
)
Expand Down

0 comments on commit 16ee899

Please sign in to comment.