mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Improve consistency of the error messages generated when you try to use
ALTER TABLE on a composite type or ALTER TYPE on a table's rowtype. We already rejected these cases, but the error messages were a bit random and didn't always provide a HINT to use the other command type.
This commit is contained in:
parent
e6022e7470
commit
34b44c3ba2
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.232 2007/09/06 17:31:58 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.233 2007/09/29 17:18:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -5430,8 +5430,16 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing)
|
||||
get_rel_name(tableId))));
|
||||
}
|
||||
break;
|
||||
case RELKIND_TOASTVALUE:
|
||||
case RELKIND_COMPOSITE_TYPE:
|
||||
if (recursing)
|
||||
break;
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is a composite type",
|
||||
NameStr(tuple_class->relname)),
|
||||
errhint("Use ALTER TYPE instead.")));
|
||||
break;
|
||||
case RELKIND_TOASTVALUE:
|
||||
if (recursing)
|
||||
break;
|
||||
/* FALL THRU */
|
||||
@ -6478,21 +6486,21 @@ AlterTableNamespace(RangeVar *relation, const char *newschema)
|
||||
Oid nspOid;
|
||||
Relation classRel;
|
||||
|
||||
rel = heap_openrv(relation, AccessExclusiveLock);
|
||||
rel = relation_openrv(relation, AccessExclusiveLock);
|
||||
|
||||
relid = RelationGetRelid(rel);
|
||||
oldNspOid = RelationGetNamespace(rel);
|
||||
|
||||
/* heap_openrv allows TOAST, but we don't want to */
|
||||
if (rel->rd_rel->relkind == RELKIND_TOASTVALUE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is a TOAST relation",
|
||||
RelationGetRelationName(rel))));
|
||||
|
||||
/* if it's an owned sequence, disallow moving it by itself */
|
||||
if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
|
||||
/* Can we change the schema of this tuple? */
|
||||
switch (rel->rd_rel->relkind)
|
||||
{
|
||||
case RELKIND_RELATION:
|
||||
case RELKIND_VIEW:
|
||||
/* ok to change schema */
|
||||
break;
|
||||
case RELKIND_SEQUENCE:
|
||||
{
|
||||
/* if it's an owned sequence, disallow moving it by itself */
|
||||
Oid tableId;
|
||||
int32 colId;
|
||||
|
||||
@ -6504,6 +6512,23 @@ AlterTableNamespace(RangeVar *relation, const char *newschema)
|
||||
RelationGetRelationName(rel),
|
||||
get_rel_name(tableId))));
|
||||
}
|
||||
break;
|
||||
case RELKIND_COMPOSITE_TYPE:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is a composite type",
|
||||
RelationGetRelationName(rel)),
|
||||
errhint("Use ALTER TYPE instead.")));
|
||||
break;
|
||||
case RELKIND_INDEX:
|
||||
case RELKIND_TOASTVALUE:
|
||||
/* FALL THRU */
|
||||
default:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is not a table, view, or sequence",
|
||||
RelationGetRelationName(rel))));
|
||||
}
|
||||
|
||||
/* get schema OID and check its permissions */
|
||||
nspOid = LookupCreationNamespace(newschema);
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.107 2007/09/04 16:41:42 adunstan Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.108 2007/09/29 17:18:58 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@ -2355,8 +2355,9 @@ AlterTypeOwner(List *names, Oid newOwnerId)
|
||||
get_rel_relkind(typTup->typrelid) != RELKIND_COMPOSITE_TYPE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is a table's row type",
|
||||
TypeNameToString(typename))));
|
||||
errmsg("%s is a table's row type",
|
||||
format_type_be(typeOid)),
|
||||
errhint("Use ALTER TABLE instead.")));
|
||||
|
||||
/* don't allow direct alteration of array types, either */
|
||||
if (OidIsValid(typTup->typelem) &&
|
||||
@ -2592,7 +2593,7 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("%s is a table's row type",
|
||||
format_type_be(typeOid)),
|
||||
errhint("Use ALTER TABLE SET SCHEMA instead.")));
|
||||
errhint("Use ALTER TABLE instead.")));
|
||||
|
||||
/* OK, modify the pg_type row */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user