diff --git a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java index aedeb05d7e91..9ecf448fa347 100644 --- a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java +++ b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java @@ -71,6 +71,7 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.IntStream.range; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertTrue; public class TestPostgreSqlConnectorTest @@ -711,6 +712,17 @@ public void testArithmeticPredicatePushdown() assertThat(query("SELECT nationkey, name, regionkey FROM nation WHERE nationkey > 0 AND (nationkey - regionkey) % nationkey = 2")) .isFullyPushedDown() .matches("VALUES (BIGINT '3', CAST('CANADA' AS varchar(25)), BIGINT '1')"); + + // some databases calculate remainder instead of modulus when one of the values is negative + assertThat(query("SELECT nationkey, name, regionkey FROM nation WHERE nationkey > 0 AND (nationkey - regionkey) % -nationkey = 2")) + .isFullyPushedDown() + .matches("VALUES (BIGINT '3', CAST('CANADA' AS varchar(25)), BIGINT '1')"); + + assertThatThrownBy(() -> query("SELECT nationkey, name, regionkey FROM nation WHERE nationkey > 0 AND (nationkey - regionkey) % 0 = 2")) + .hasMessageContaining("ERROR: division by zero"); + // Expression that evaluates to 0 for some rows on RHS of modulus + assertThatThrownBy(() -> query("SELECT nationkey, name, regionkey FROM nation WHERE nationkey > 0 AND (nationkey - regionkey) % (regionkey - 1) = 2")) + .hasMessageContaining("ERROR: division by zero"); } @Test