Skip to content

Commit

Permalink
feat: execute LEFT and RIGHT (#1821)
Browse files Browse the repository at this point in the history
  • Loading branch information
barakalon authored Jun 23, 2023
1 parent 2367bfc commit 5572e76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sqlglot/executor/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def interval(this, unit):
"IF": lambda predicate, true, false: true if predicate else false,
"INTDIV": null_if_any(lambda e, this: e // this),
"INTERVAL": interval,
"LEFT": null_if_any(lambda this, e: this[:e]),
"LIKE": null_if_any(
lambda this, e: bool(re.match(e.replace("_", ".").replace("%", ".*"), this))
),
Expand All @@ -176,6 +177,7 @@ def interval(this, unit):
"ORD": null_if_any(ord),
"ORDERED": ordered,
"POW": pow,
"RIGHT": null_if_any(lambda this, e: this[-e:]),
"STRPOSITION": str_position,
"SUB": null_if_any(lambda e, this: e - this),
"SUBSTRING": substring,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ def test_scalar_functions(self):
("STRFTIME('%j', NULL)", None),
("DATESTRTODATE('2022-01-01')", date(2022, 1, 1)),
("TIMESTRTOTIME('2022-01-01')", datetime.datetime(2022, 1, 1)),
("LEFT('12345', 3)", "123"),
("RIGHT('12345', 3)", "345"),
]:
with self.subTest(sql):
result = execute(f"SELECT {sql}")
Expand Down

0 comments on commit 5572e76

Please sign in to comment.