-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(oracle)!: interval expressions #6648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d941a42
7a5b524
ad70e85
32a9390
1c5bf13
d53cf0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,7 +172,14 @@ class Parser(parser.Parser): | |
| TYPE_LITERAL_PARSERS = { | ||
| exp.DataType.Type.DATE: lambda self, this, _: self.expression( | ||
| exp.DateStrToDate, this=this | ||
| ) | ||
| ), | ||
| exp.DataType.Type.TIMESTAMP: lambda self, this, _: self.expression( | ||
| exp.StrToTime, | ||
| this=this, | ||
| format=exp.Literal.string( | ||
| "%Y-%m-%d %H:%M:%S.%f" if "." in this.name else "%Y-%m-%d %H:%M:%S" | ||
| ), | ||
| ), | ||
| } | ||
|
|
||
| # SELECT UNIQUE .. is old-style Oracle syntax for SELECT DISTINCT .. | ||
|
|
@@ -275,6 +282,25 @@ def _parse_into(self) -> t.Optional[exp.Into]: | |
| def _parse_connect_with_prior(self): | ||
| return self._parse_assignment() | ||
|
|
||
| def _parse_column_ops(self, this: t.Optional[exp.Expression]) -> t.Optional[exp.Expression]: | ||
| this = super()._parse_column_ops(this) | ||
|
|
||
| if not this: | ||
| return this | ||
|
|
||
| index = self._index | ||
| unit = self._parse_function() or self._parse_var(any_token=True, upper=True) | ||
|
|
||
| if unit and self._match_text_seq("TO"): | ||
| to_unit = self._parse_function() or self._parse_var(any_token=True, upper=True) | ||
|
|
||
| if to_unit: | ||
| unit = exp.IntervalSpan(this=unit, expression=to_unit) | ||
| return self.expression(exp.Interval, this=this, unit=unit) | ||
|
Comment on lines
+294
to
+299
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like we're repeating existing parts of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the similarity, but I'm struggling to find a clean way to merge the logic 🙂 |
||
|
|
||
| self._retreat(index) | ||
| return this | ||
|
|
||
| def _parse_insert_table(self) -> t.Optional[exp.Expression]: | ||
| # Oracle does not use AS for INSERT INTO alias | ||
| # https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/INSERT.html | ||
|
|
@@ -420,3 +446,6 @@ def hint_sql(self, expression: exp.Hint) -> str: | |
|
|
||
| def isascii_sql(self, expression: exp.IsAscii) -> str: | ||
| return f"NVL(REGEXP_LIKE({self.sql(expression.this)}, '^[' || CHR(1) || '-' || CHR(127) || ']*$'), TRUE)" | ||
|
|
||
| def interval_sql(self, expression: exp.Interval) -> str: | ||
| return f"{'INTERVAL ' if isinstance(expression.this, exp.Literal) else ''}{self.sql(expression, 'this')} {self.sql(expression, 'unit')}" | ||
Uh oh!
There was an error while loading. Please reload this page.