Fix incorrect Assert; install a more trustworthy check on whether

ALTER COLUMN SET STORAGE should be allowed.
This commit is contained in:
Tom Lane 2002-04-22 21:46:11 +00:00
parent fccda9eb90
commit 3faf224ace
1 changed files with 20 additions and 14 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.5 2002/04/19 23:13:54 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.6 2002/04/22 21:46:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -771,10 +771,10 @@ AlterTableAlterColumnFlags(Oid myrelid,
{ {
Relation rel; Relation rel;
int newtarget = 1; int newtarget = 1;
char newstorage = 'x'; char newstorage = 'p';
char *storagemode;
Relation attrelation; Relation attrelation;
HeapTuple tuple; HeapTuple tuple;
Form_pg_attribute attrtuple;
rel = heap_open(myrelid, AccessExclusiveLock); rel = heap_open(myrelid, AccessExclusiveLock);
@ -813,9 +813,11 @@ AlterTableAlterColumnFlags(Oid myrelid,
else if (*flagType == 'M') else if (*flagType == 'M')
{ {
/* STORAGE */ /* STORAGE */
Assert(IsA(flagValue, Value)); char *storagemode;
Assert(IsA(flagValue, String));
storagemode = strVal(flagValue); storagemode = strVal(flagValue);
if (strcasecmp(storagemode, "plain") == 0) if (strcasecmp(storagemode, "plain") == 0)
newstorage = 'p'; newstorage = 'p';
else if (strcasecmp(storagemode, "external") == 0) else if (strcasecmp(storagemode, "external") == 0)
@ -872,26 +874,30 @@ AlterTableAlterColumnFlags(Oid myrelid,
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "ALTER TABLE: relation \"%s\" has no column \"%s\"", elog(ERROR, "ALTER TABLE: relation \"%s\" has no column \"%s\"",
RelationGetRelationName(rel), colName); RelationGetRelationName(rel), colName);
attrtuple = (Form_pg_attribute) GETSTRUCT(tuple);
if (((Form_pg_attribute) GETSTRUCT(tuple))->attnum < 0) if (attrtuple->attnum < 0)
elog(ERROR, "ALTER TABLE: cannot change system attribute \"%s\"", elog(ERROR, "ALTER TABLE: cannot change system attribute \"%s\"",
colName); colName);
/* /*
* Now change the appropriate field * Now change the appropriate field
*/ */
if (*flagType == 'S') if (*flagType == 'S')
((Form_pg_attribute) GETSTRUCT(tuple))->attstattarget = newtarget; attrtuple->attstattarget = newtarget;
else else if (*flagType == 'M')
{ {
if ((newstorage == 'p') || /*
(((Form_pg_attribute) GETSTRUCT(tuple))->attlen == -1)) * safety check: do not allow toasted storage modes unless column
((Form_pg_attribute) GETSTRUCT(tuple))->attstorage = newstorage; * datatype is TOAST-aware. We assume the datatype's typstorage
* will be 'p' if and only if it ain't TOAST-aware.
*/
if (newstorage == 'p' || get_typstorage(attrtuple->atttypid) != 'p')
attrtuple->attstorage = newstorage;
else else
{ elog(ERROR, "ALTER TABLE: Column datatype %s can only have storage \"plain\"",
elog(ERROR, format_type_be(attrtuple->atttypid));
"ALTER TABLE: Fixed-length columns can only have storage \"plain\"");
}
} }
simple_heap_update(attrelation, &tuple->t_self, tuple); simple_heap_update(attrelation, &tuple->t_self, tuple);
/* keep system catalog indices current */ /* keep system catalog indices current */