in ext/pg_query/pg_query_deparse.c [7241:7292]
static void deparseGrantStmt(StringInfo str, GrantStmt *grant_stmt)
{
ListCell *lc;
if (grant_stmt->is_grant)
appendStringInfoString(str, "GRANT ");
else
appendStringInfoString(str, "REVOKE ");
if (!grant_stmt->is_grant && grant_stmt->grant_option)
appendStringInfoString(str, "GRANT OPTION FOR ");
if (list_length(grant_stmt->privileges) > 0)
{
foreach(lc, grant_stmt->privileges)
{
deparseAccessPriv(str, castNode(AccessPriv, lfirst(lc)));
if (lnext(grant_stmt->privileges, lc))
appendStringInfoString(str, ", ");
}
appendStringInfoChar(str, ' ');
}
else
{
appendStringInfoString(str, "ALL ");
}
appendStringInfoString(str, "ON ");
deparsePrivilegeTarget(str, grant_stmt->targtype, grant_stmt->objtype, grant_stmt->objects);
appendStringInfoChar(str, ' ');
if (grant_stmt->is_grant)
appendStringInfoString(str, "TO ");
else
appendStringInfoString(str, "FROM ");
foreach(lc, grant_stmt->grantees)
{
deparseRoleSpec(str, castNode(RoleSpec, lfirst(lc)));
if (lnext(grant_stmt->grantees, lc))
appendStringInfoChar(str, ',');
appendStringInfoChar(str, ' ');
}
if (grant_stmt->is_grant && grant_stmt->grant_option)
appendStringInfoString(str, "WITH GRANT OPTION ");
deparseOptDropBehavior(str, grant_stmt->behavior);
removeTrailingSpace(str);
}