diff --git a/src/backend/distributed/deparser/deparse_role_stmts.c b/src/backend/distributed/deparser/deparse_role_stmts.c index 7180c620d..8377e23bc 100644 --- a/src/backend/distributed/deparser/deparse_role_stmts.c +++ b/src/backend/distributed/deparser/deparse_role_stmts.c @@ -15,6 +15,7 @@ #include "pg_version_compat.h" +#include "commands/defrem.h" #include "commands/defrem.h" #include "distributed/citus_ruleutils.h" #include "distributed/deparser.h" @@ -451,20 +452,12 @@ AppendGrantWithAdminOption(StringInfo buf, GrantRoleStmt *stmt) DefElem *opt = NULL; foreach_ptr(opt, stmt->opt) { - switch (opt->defname) - { - case "admin": - appendStringInfo(buf, " WITH ADMIN OPTION"); - opt_count++; - break; - - case "inherit": - if (opt_count > 0) - { - appendStringInfo(buf, ", "); - } - appendStringInfo(buf, "INHERIT OPTION "); - opt_count++; + bool admin_option = false; + char *optval = defGetString(opt); + if (strcmp(opt->defname, "admin") == 0 && + parse_bool(optval, &admin_option) && admin_option) + { + appendStringInfo(buf, " WITH ADMIN OPTION"); break; diff --git a/src/test/regress/sql/pg16.sql b/src/test/regress/sql/pg16.sql index 30f2731e6..61cfe17a5 100644 --- a/src/test/regress/sql/pg16.sql +++ b/src/test/regress/sql/pg16.sql @@ -746,6 +746,32 @@ REVOKE role1 FROM role2; RESET citus.log_remote_commands; RESET citus.grep_remote_commands; +-- +-- PG16 added WITH ADMIN FALSE option to GRANT ROLE +-- WITH ADMIN FALSE is the default, make sure we propagate correctly in Citus +-- Relevant PG commit: https://github.com/postgres/postgres/commit/e3ce2de +-- + +CREATE ROLE role1; +CREATE ROLE role2; + +SET citus.log_remote_commands TO on; +SET citus.grep_remote_commands = '%GRANT%'; +-- default admin option is false +GRANT role1 TO role2; +REVOKE role1 FROM role2; +-- should behave same as default +GRANT role1 TO role2 WITH ADMIN FALSE; +REVOKE role1 FROM role2; +-- with admin option and with admin true are the same +GRANT role1 TO role2 WITH ADMIN OPTION; +REVOKE role1 FROM role2; +GRANT role1 TO role2 WITH ADMIN TRUE; +REVOKE role1 FROM role2; + +RESET citus.log_remote_commands; +RESET citus.grep_remote_commands; + -- -- PG16 added new options to GRANT ROLE -- inherit: https://github.com/postgres/postgres/commit/e3ce2de