88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.332 2010/07/06 19:18:56 momjian Exp $
11+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.333 2010/07/23 20:04:18 petere Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -288,6 +288,7 @@ static void ATExecSetOptions(Relation rel, const char *colName,
288288Node * options ,bool isReset );
289289static void ATExecSetStorage (Relation rel ,const char * colName ,
290290Node * newValue );
291+ static void ATPrepDropColumn (Relation rel ,bool recurse ,AlterTableCmd * cmd );
291292static void ATExecDropColumn (List * * wqueue ,Relation rel ,const char * colName ,
292293DropBehavior behavior ,
293294bool recurse ,bool recursing ,
@@ -327,7 +328,8 @@ static void ATExecEnableDisableTrigger(Relation rel, char *trigname,
327328char fires_when ,bool skip_system );
328329static void ATExecEnableDisableRule (Relation rel ,char * rulename ,
329330char fires_when );
330- static void ATExecAddInherit (Relation rel ,RangeVar * parent );
331+ static void ATPrepAddInherit (Relation child_rel );
332+ static void ATExecAddInherit (Relation child_rel ,RangeVar * parent );
331333static void ATExecDropInherit (Relation rel ,RangeVar * parent );
332334static void copy_relation_data (SMgrRelation rel ,SMgrRelation dst ,
333335ForkNumber forkNum ,bool istemp );
@@ -2499,10 +2501,8 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
24992501break ;
25002502case AT_DropColumn :/* DROP COLUMN */
25012503ATSimplePermissions (rel , false);
2504+ ATPrepDropColumn (rel ,recurse ,cmd );
25022505/* Recursion occurs during execution phase */
2503- /* No command-specific prep needed except saving recurse flag */
2504- if (recurse )
2505- cmd -> subtype = AT_DropColumnRecurse ;
25062506pass = AT_PASS_DROP ;
25072507break ;
25082508case AT_AddIndex :/* ADD INDEX */
@@ -2579,6 +2579,12 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
25792579/* No command-specific prep needed */
25802580pass = AT_PASS_MISC ;
25812581break ;
2582+ case AT_AddInherit :/* INHERIT */
2583+ ATSimplePermissions (rel , false);
2584+ /* This command never recurses */
2585+ ATPrepAddInherit (rel );
2586+ pass = AT_PASS_MISC ;
2587+ break ;
25822588case AT_EnableTrig :/* ENABLE TRIGGER variants */
25832589case AT_EnableAlwaysTrig :
25842590case AT_EnableReplicaTrig :
@@ -2591,8 +2597,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
25912597case AT_EnableAlwaysRule :
25922598case AT_EnableReplicaRule :
25932599case AT_DisableRule :
2594- case AT_AddInherit :/* INHERIT / NO INHERIT */
2595- case AT_DropInherit :
2600+ case AT_DropInherit :/* NO INHERIT */
25962601ATSimplePermissions (rel , false);
25972602/* These commands never recurse */
25982603/* No command-specific prep needed */
@@ -3568,6 +3573,11 @@ static void
35683573ATPrepAddColumn (List * * wqueue ,Relation rel ,bool recurse ,
35693574AlterTableCmd * cmd )
35703575{
3576+ if (rel -> rd_rel -> reloftype )
3577+ ereport (ERROR ,
3578+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
3579+ errmsg ("cannot add column to typed table" )));
3580+
35713581/*
35723582 * Recurse to add the column to child classes, if requested.
35733583 *
@@ -3616,11 +3626,6 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
36163626Form_pg_type tform ;
36173627Expr * defval ;
36183628
3619- if (rel -> rd_rel -> reloftype )
3620- ereport (ERROR ,
3621- (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
3622- errmsg ("cannot add column to typed table" )));
3623-
36243629attrdesc = heap_open (AttributeRelationId ,RowExclusiveLock );
36253630
36263631/*
@@ -4325,6 +4330,19 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue)
43254330 * static pre-pass because it won't handle multiple inheritance situations
43264331 * correctly.)
43274332 */
4333+ static void
4334+ ATPrepDropColumn (Relation rel ,bool recurse ,AlterTableCmd * cmd )
4335+ {
4336+ if (rel -> rd_rel -> reloftype )
4337+ ereport (ERROR ,
4338+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
4339+ errmsg ("cannot drop column from typed table" )));
4340+
4341+ /* No command-specific prep needed except saving recurse flag */
4342+ if (recurse )
4343+ cmd -> subtype = AT_DropColumnRecurse ;
4344+ }
4345+
43284346static void
43294347ATExecDropColumn (List * * wqueue ,Relation rel ,const char * colName ,
43304348DropBehavior behavior ,
@@ -4337,11 +4355,6 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
43374355List * children ;
43384356ObjectAddress object ;
43394357
4340- if (rel -> rd_rel -> reloftype )
4341- ereport (ERROR ,
4342- (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
4343- errmsg ("cannot drop column from typed table" )));
4344-
43454358/* At top level, permission check was done in ATPrepCmd, else do it */
43464359if (recursing )
43474360ATSimplePermissions (rel , false);
@@ -5788,6 +5801,11 @@ ATPrepAlterColumnType(List **wqueue,
57885801NewColumnValue * newval ;
57895802ParseState * pstate = make_parsestate (NULL );
57905803
5804+ if (rel -> rd_rel -> reloftype )
5805+ ereport (ERROR ,
5806+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
5807+ errmsg ("cannot alter column type of typed table" )));
5808+
57915809/* lookup the attribute so we can check inheritance status */
57925810tuple = SearchSysCacheAttName (RelationGetRelid (rel ),colName );
57935811if (!HeapTupleIsValid (tuple ))
@@ -7115,6 +7133,15 @@ ATExecEnableDisableRule(Relation rel, char *trigname,
71157133 * check constraints of the parent appear in the child and that they have the
71167134 * same data types and expressions.
71177135 */
7136+ static void
7137+ ATPrepAddInherit (Relation child_rel )
7138+ {
7139+ if (child_rel -> rd_rel -> reloftype )
7140+ ereport (ERROR ,
7141+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
7142+ errmsg ("cannot change inheritance of typed table" )));
7143+ }
7144+
71187145static void
71197146ATExecAddInherit (Relation child_rel ,RangeVar * parent )
71207147{