Skip to content
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

Fix(postgres, redshift): use single string interval logic #1651

Merged
merged 1 commit into from
May 18, 2023

Conversation

georgesittas
Copy link
Collaborator

Fixes #1649

@@ -304,7 +304,7 @@ def _parse_date_part(self) -> exp.Expression:
return self.expression(exp.Extract, this=part, expression=value)

class Generator(generator.Generator):
INTERVAL_ALLOWS_PLURAL_FORM = False
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested against both engines (postgres, redshift), this was invalid as plural forms are allowed.

@@ -1852,7 +1852,7 @@ def interval_sql(self, expression: exp.Interval) -> str:

if self.SINGLE_STRING_INTERVAL:
this = expression.this.name if expression.this else ""
return f"INTERVAL '{this}{unit}'"
return f"INTERVAL '{this}{unit}'" if this else f"INTERVAL{unit}"
Copy link
Collaborator Author

@georgesittas georgesittas May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed because we can have value::interval day, which would be transpiled to cast(value as interval ' day'), but it should be transpiled to cast(value as interval day).

@tobymao tobymao merged commit 6f9d531 into main May 18, 2023
@tobymao tobymao deleted the jo/interval_fixup branch May 18, 2023 17:13
adrianisk pushed a commit to adrianisk/sqlglot that referenced this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres interval not formatted correctly
2 participants