|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.5 2002/04/19 23:13:54 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.6 2002/04/22 21:46:11 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -771,10 +771,10 @@ AlterTableAlterColumnFlags(Oid myrelid, |
771 | 771 | { |
772 | 772 | Relationrel; |
773 | 773 | intnewtarget=1; |
774 | | -charnewstorage='x'; |
775 | | -char*storagemode; |
| 774 | +charnewstorage='p'; |
776 | 775 | Relationattrelation; |
777 | 776 | HeapTupletuple; |
| 777 | +Form_pg_attributeattrtuple; |
778 | 778 |
|
779 | 779 | rel=heap_open(myrelid,AccessExclusiveLock); |
780 | 780 |
|
@@ -813,9 +813,11 @@ AlterTableAlterColumnFlags(Oid myrelid, |
813 | 813 | elseif (*flagType=='M') |
814 | 814 | { |
815 | 815 | /* STORAGE */ |
816 | | -Assert(IsA(flagValue,Value)); |
| 816 | +char*storagemode; |
817 | 817 |
|
| 818 | +Assert(IsA(flagValue,String)); |
818 | 819 | storagemode=strVal(flagValue); |
| 820 | + |
819 | 821 | if (strcasecmp(storagemode,"plain")==0) |
820 | 822 | newstorage='p'; |
821 | 823 | elseif (strcasecmp(storagemode,"external")==0) |
@@ -872,26 +874,30 @@ AlterTableAlterColumnFlags(Oid myrelid, |
872 | 874 | if (!HeapTupleIsValid(tuple)) |
873 | 875 | elog(ERROR,"ALTER TABLE: relation \"%s\" has no column \"%s\"", |
874 | 876 | RelationGetRelationName(rel),colName); |
| 877 | +attrtuple= (Form_pg_attribute)GETSTRUCT(tuple); |
875 | 878 |
|
876 | | -if (((Form_pg_attribute)GETSTRUCT(tuple))->attnum<0) |
| 879 | +if (attrtuple->attnum<0) |
877 | 880 | elog(ERROR,"ALTER TABLE: cannot change system attribute \"%s\"", |
878 | 881 | colName); |
879 | 882 | /* |
880 | 883 | * Now change the appropriate field |
881 | 884 | */ |
882 | 885 | if (*flagType=='S') |
883 | | -((Form_pg_attribute)GETSTRUCT(tuple))->attstattarget=newtarget; |
884 | | -else |
| 886 | +attrtuple->attstattarget=newtarget; |
| 887 | +elseif (*flagType=='M') |
885 | 888 | { |
886 | | -if ((newstorage=='p')|| |
887 | | -(((Form_pg_attribute)GETSTRUCT(tuple))->attlen==-1)) |
888 | | -((Form_pg_attribute)GETSTRUCT(tuple))->attstorage=newstorage; |
| 889 | +/* |
| 890 | + * safety check: do not allow toasted storage modes unless column |
| 891 | + * datatype is TOAST-aware. We assume the datatype's typstorage |
| 892 | + * will be 'p' if and only if it ain't TOAST-aware. |
| 893 | + */ |
| 894 | +if (newstorage=='p'||get_typstorage(attrtuple->atttypid)!='p') |
| 895 | +attrtuple->attstorage=newstorage; |
889 | 896 | else |
890 | | -{ |
891 | | -elog(ERROR, |
892 | | -"ALTER TABLE: Fixed-length columns can only have storage \"plain\""); |
893 | | -} |
| 897 | +elog(ERROR,"ALTER TABLE: Column datatype %s can only have storage \"plain\"", |
| 898 | +format_type_be(attrtuple->atttypid)); |
894 | 899 | } |
| 900 | + |
895 | 901 | simple_heap_update(attrelation,&tuple->t_self,tuple); |
896 | 902 |
|
897 | 903 | /* keep system catalog indices current */ |
|