Skip to content

Commit

Permalink
fix: convert regex sql to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
longxiaofei committed May 29, 2024
1 parent 2f6830a commit 614f938
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pygwalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pygwalker.services.global_var import GlobalVarManager
from pygwalker.services.kaggle import show_tips_user_kaggle as __show_tips_user_kaggle

__version__ = "0.4.8.7"
__version__ = "0.4.8.8"
__hash__ = __rand_str()

from pygwalker.api.jupyter import walk, render, table
Expand Down
8 changes: 8 additions & 0 deletions pygwalker/utils/custom_sqlglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ def _postgres_str_to_time_sql(self: Generator, expression: exp.StrToTime) -> str
return self.func("TO_TIMESTAMP", expression.this, self.format_time(expression))


def _postgres_regexp_like_sql(self: Generator, expression: exp.RegexpLike) -> str:
flag = expression.args.get("flag")
if flag and flag.this == "i":
return self.binary(expression, "~*")
return self.binary(expression, "~")


PostgresDialect.Generator.TRANSFORMS[exp.Round] = lambda _, e: _postgres_round_generator(e)
PostgresDialect.Generator.TRANSFORMS[exp.UnixToTime] = _postgres_unix_to_time_sql
PostgresDialect.Generator.TRANSFORMS[exp.In] = _postgres_in_sql
PostgresDialect.Generator.TRANSFORMS[exp.TimestampTrunc] = _postgres_timestamp_trunc
PostgresDialect.Generator.TRANSFORMS[exp.TimeToStr] = _postgres_time_to_str_sql
PostgresDialect.Generator.TRANSFORMS[exp.StrToTime] = _postgres_str_to_time_sql
PostgresDialect.Generator.TRANSFORMS[exp.RegexpLike] = _postgres_regexp_like_sql


# Mysql Dialect
Expand Down

0 comments on commit 614f938

Please sign in to comment.