Example #1
0
/*
 * Executes an ALTER OBJECT / RENAME TO statement.	Based on the object
 * type, the function appropriate to that type is executed.
 */
void
ExecRenameStmt(RenameStmt *stmt)
{
    switch (stmt->renameType)
    {
    case OBJECT_AGGREGATE:
        RenameAggregate(stmt->object, stmt->objarg, stmt->newname);
        break;

    case OBJECT_CONVERSION:
        RenameConversion(stmt->object, stmt->newname);
        break;

    case OBJECT_DATABASE:
        RenameDatabase(stmt->subname, stmt->newname);
        break;

    case OBJECT_FUNCTION:
        RenameFunction(stmt->object, stmt->objarg, stmt->newname);
        break;

    case OBJECT_LANGUAGE:
        RenameLanguage(stmt->subname, stmt->newname);
        break;

    case OBJECT_OPCLASS:
        RenameOpClass(stmt->object, stmt->subname, stmt->newname);
        break;

    case OBJECT_ROLE:
        RenameRole(stmt->subname, stmt->newname);
        break;

    case OBJECT_SCHEMA:
        RenameSchema(stmt->subname, stmt->newname);
        break;

    case OBJECT_TABLESPACE:
        RenameTableSpace(stmt->subname, stmt->newname);
        break;

    case OBJECT_TABLE:
    case OBJECT_INDEX:
    case OBJECT_COLUMN:
    case OBJECT_TRIGGER:
    {
        Oid			relid;

        CheckRelationOwnership(stmt->relation, true);

        relid = RangeVarGetRelid(stmt->relation, false);

        switch (stmt->renameType)
        {
        case OBJECT_TABLE:
        case OBJECT_INDEX:
        {
            /*
             * RENAME TABLE requires that we (still) hold
             * CREATE rights on the containing namespace, as
             * well as ownership of the table.
             */
            Oid			namespaceId = get_rel_namespace(relid);
            AclResult	aclresult;

            aclresult = pg_namespace_aclcheck(namespaceId,
                                              GetUserId(),
                                              ACL_CREATE);
            if (aclresult != ACLCHECK_OK)
                aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
                               get_namespace_name(namespaceId));

            renamerel(relid, stmt->newname);
            break;
        }
        case OBJECT_COLUMN:
            renameatt(relid,
                      stmt->subname,		/* old att name */
                      stmt->newname,		/* new att name */
                      interpretInhOption(stmt->relation->inhOpt),	/* recursive? */
                      false);		/* recursing already? */
            break;
        case OBJECT_TRIGGER:
            renametrig(relid,
                       stmt->subname,		/* old att name */
                       stmt->newname);		/* new att name */
            break;
        default:
            /* can't happen */
            ;
        }
        break;
    }

    default:
        elog(ERROR, "unrecognized rename stmt type: %d",
             (int) stmt->renameType);
    }
}
Example #2
0
/*
 * Executes an ALTER OBJECT / RENAME TO statement.	Based on the object
 * type, the function appropriate to that type is executed.
 */
void
ExecRenameStmt(RenameStmt *stmt)
{
	switch (stmt->renameType)
	{
		case OBJECT_AGGREGATE:
			RenameAggregate(stmt->object, stmt->objarg, stmt->newname);
			break;

		case OBJECT_CONVERSION:
			RenameConversion(stmt->object, stmt->newname);
			break;

		case OBJECT_DATABASE:
			RenameDatabase(stmt->subname, stmt->newname);
			break;

		case OBJECT_EXTPROTOCOL:
			RenameExtProtocol(stmt->subname, stmt->newname);
			break;

		case OBJECT_FUNCTION:
			RenameFunction(stmt->object, stmt->objarg, stmt->newname);
			break;

		case OBJECT_LANGUAGE:
			RenameLanguage(stmt->subname, stmt->newname);
			break;

		case OBJECT_OPCLASS:
			RenameOpClass(stmt->object, stmt->subname, stmt->newname);
			break;

		case OBJECT_OPFAMILY:
			RenameOpFamily(stmt->object, stmt->subname, stmt->newname);
			break;

		case OBJECT_ROLE:
			RenameRole(stmt->subname, stmt->newname);
			break;

		case OBJECT_SCHEMA:
			RenameSchema(stmt->subname, stmt->newname);
			break;

		case OBJECT_TABLESPACE:
			RenameTableSpace(stmt->subname, stmt->newname);
			break;

		case OBJECT_FILESPACE:
			RenameFileSpace(stmt->subname, stmt->newname);
			break;

		case OBJECT_TABLE:
		case OBJECT_SEQUENCE:
		case OBJECT_VIEW:
		case OBJECT_INDEX:
		{
			if (Gp_role == GP_ROLE_DISPATCH)
			{
				CheckRelationOwnership(stmt->relation, true);
				stmt->objid = RangeVarGetRelid(stmt->relation, false);
			}

			/*
			 * RENAME TABLE requires that we (still) hold
			 * CREATE rights on the containing namespace, as
			 * well as ownership of the table.
			 */
			Oid			namespaceId = get_rel_namespace(stmt->objid);
			AclResult	aclresult;

			aclresult = pg_namespace_aclcheck(namespaceId,
											  GetUserId(),
											  ACL_CREATE);
			if (aclresult != ACLCHECK_OK)
				aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
							   get_namespace_name(namespaceId));

			renamerel(stmt->objid, stmt->newname, stmt->renameType, stmt);
			break;
		}

		case OBJECT_COLUMN:
		case OBJECT_TRIGGER:
			{
				Oid			relid;

				CheckRelationOwnership(stmt->relation, true);

				relid = RangeVarGetRelid(stmt->relation, false);

				switch (stmt->renameType)
				{
					case OBJECT_COLUMN:
						renameatt(relid,
								  stmt->subname,		/* old att name */
								  stmt->newname,		/* new att name */
								  interpretInhOption(stmt->relation->inhOpt),	/* recursive? */
								  false);		/* recursing already? */
						break;
					case OBJECT_TRIGGER:
						renametrig(relid,
								   stmt->subname,		/* old att name */
								   stmt->newname);		/* new att name */
						break;
					default:
						 /* can't happen */ ;
				}
				break;
			}

		case OBJECT_TSPARSER:
			RenameTSParser(stmt->object, stmt->newname);
			break;

		case OBJECT_TSDICTIONARY:
			RenameTSDictionary(stmt->object, stmt->newname);
			break;

		case OBJECT_TSTEMPLATE:
			RenameTSTemplate(stmt->object, stmt->newname);
			break;

		case OBJECT_TSCONFIGURATION:
			RenameTSConfiguration(stmt->object, stmt->newname);
			break;

		default:
			elog(ERROR, "unrecognized rename stmt type: %d",
				 (int) stmt->renameType);
	}
	if (Gp_role == GP_ROLE_DISPATCH)
	{
		CdbDispatchUtilityStatement((Node *) stmt, "ExecRenameStmt");
	}

}