diff --git a/sqlalchemy_bigquery/base.py b/sqlalchemy_bigquery/base.py index cffb9daa..38d8f5c1 100644 --- a/sqlalchemy_bigquery/base.py +++ b/sqlalchemy_bigquery/base.py @@ -581,6 +581,9 @@ def visit_regexp_match_op_binary(self, binary, operator, **kw): def visit_not_regexp_match_op_binary(self, binary, operator, **kw): return "NOT %s" % self.visit_regexp_match_op_binary(binary, operator, **kw) + def visit_mod_binary(self, binary, operator, **kw): + return f"MOD({self.process(binary.left, **kw)}, {self.process(binary.right, **kw)})" + class BigQueryTypeCompiler(GenericTypeCompiler): def visit_INTEGER(self, type_, **kw): diff --git a/tests/unit/test_select.py b/tests/unit/test_select.py index ad80047a..07f21443 100644 --- a/tests/unit/test_select.py +++ b/tests/unit/test_select.py @@ -406,3 +406,16 @@ def test_visit_not_regexp_match_op_binary(faux_conn): expected = "NOT REGEXP_CONTAINS(`table`.`foo`, %(foo_1:STRING)s)" assert result == expected + + +def test_visit_mod_binary(faux_conn): + table = setup_table( + faux_conn, + "table", + sqlalchemy.Column("foo", sqlalchemy.Integer), + ) + sql_statement = table.c.foo % 2 + result = sql_statement.compile(faux_conn).string + expected = "MOD(`table`.`foo`, %(foo_1:INT64)s)" + + assert result == expected