Skip to content

Commit

Permalink
Feat: add as_ builder
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed May 16, 2023
1 parent b9140b6 commit 51e8b1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,16 @@ def not_(self, copy=True):
"""
return not_(self, copy=copy)

def as_(
self,
alias: str | Identifier,
quoted: t.Optional[bool] = None,
dialect: DialectType = None,
copy: bool = True,
**opts,
) -> exp.Alias:
return alias_(self, alias, quoted=quoted, dialect=dialect, copy=copy, **opts)

def _binop(self, klass: t.Type[E], other: t.Any, reverse: bool = False) -> E:
this = self.copy()
other = convert(other, copy=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_build(self):
(lambda: x.eq(1), "x = 1"),
(lambda: x.neq(1), "x <> 1"),
(lambda: x.is_(exp.Null()), "x IS NULL"),
(lambda: x.as_("y"), "x AS y"),
(lambda: x.isin(1, "2"), "x IN (1, '2')"),
(lambda: x.isin(query="select 1"), "x IN (SELECT 1)"),
(lambda: x.between(1, 2), "x BETWEEN 1 AND 2"),
Expand Down

0 comments on commit 51e8b1f

Please sign in to comment.