diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 2f7d80e..a815ad3 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -1574,6 +1574,22 @@ top: } snprintf(res, sizeof(res), INT64_FORMAT, ope1 / ope2); } + else if (strcmp(argv[3], "%") == 0) + { + int64_t remainder; + if (ope2 == 0) + { + fprintf(stderr, "%s: division by zero in modulo\n", argv[0]); + st->ecnt++; + return true; + } + /* divisor signed remainder */ + remainder = ope1 % ope2; + if ((ope2 < 0 && remainder > 0) || + (ope2 > 0 && remainder < 0)) + remainder += ope2; + snprintf(res, sizeof(res), INT64_FORMAT, remainder); + } else { fprintf(stderr, "%s: unsupported operator %s\n", argv[0], argv[3]); diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml index b479105..66ec622 100644 --- a/doc/src/sgml/pgbench.sgml +++ b/doc/src/sgml/pgbench.sgml @@ -735,7 +735,9 @@ pgbench options dbname Each operand is either an integer constant or a :variablename reference to a variable having an integer value. The operator can be - +, -, *, or /. + +, -, *, / or %. + The modulo operation (%) is based on the floored division, so + that the remainder keeps the sign of the divisor.