Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3faf224

Browse files
committed
Fix incorrect Assert; install a more trustworthy check on whether
ALTER COLUMN SET STORAGE should be allowed.
1 parentfccda9e commit3faf224

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* 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 $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -771,10 +771,10 @@ AlterTableAlterColumnFlags(Oid myrelid,
771771
{
772772
Relationrel;
773773
intnewtarget=1;
774-
charnewstorage='x';
775-
char*storagemode;
774+
charnewstorage='p';
776775
Relationattrelation;
777776
HeapTupletuple;
777+
Form_pg_attributeattrtuple;
778778

779779
rel=heap_open(myrelid,AccessExclusiveLock);
780780

@@ -813,9 +813,11 @@ AlterTableAlterColumnFlags(Oid myrelid,
813813
elseif (*flagType=='M')
814814
{
815815
/* STORAGE */
816-
Assert(IsA(flagValue,Value));
816+
char*storagemode;
817817

818+
Assert(IsA(flagValue,String));
818819
storagemode=strVal(flagValue);
820+
819821
if (strcasecmp(storagemode,"plain")==0)
820822
newstorage='p';
821823
elseif (strcasecmp(storagemode,"external")==0)
@@ -872,26 +874,30 @@ AlterTableAlterColumnFlags(Oid myrelid,
872874
if (!HeapTupleIsValid(tuple))
873875
elog(ERROR,"ALTER TABLE: relation \"%s\" has no column \"%s\"",
874876
RelationGetRelationName(rel),colName);
877+
attrtuple= (Form_pg_attribute)GETSTRUCT(tuple);
875878

876-
if (((Form_pg_attribute)GETSTRUCT(tuple))->attnum<0)
879+
if (attrtuple->attnum<0)
877880
elog(ERROR,"ALTER TABLE: cannot change system attribute \"%s\"",
878881
colName);
879882
/*
880883
* Now change the appropriate field
881884
*/
882885
if (*flagType=='S')
883-
((Form_pg_attribute)GETSTRUCT(tuple))->attstattarget=newtarget;
884-
else
886+
attrtuple->attstattarget=newtarget;
887+
elseif (*flagType=='M')
885888
{
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;
889896
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));
894899
}
900+
895901
simple_heap_update(attrelation,&tuple->t_self,tuple);
896902

897903
/* keep system catalog indices current */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp