88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.201 2002/05/21 22:05:53 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.202 2002/05/22 07:46:58 inoue Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -353,7 +353,7 @@ heap_storage_create(Relation rel)
353353 * --------------------------------
354354 */
355355static void
356- CheckAttributeNames (TupleDesc tupdesc ,bool relhasoids )
356+ CheckAttributeNames (TupleDesc tupdesc ,bool relhasoids , int relkind )
357357{
358358int i ;
359359int j ;
@@ -365,17 +365,18 @@ CheckAttributeNames(TupleDesc tupdesc, bool relhasoids)
365365 * also, warn user if attribute to be created has an unknown typid
366366 * (usually as a result of a 'retrieve into' - jolly
367367 */
368- for (i = 0 ;i < natts ;i ++ )
369- {
370- if (SystemAttributeByName (NameStr (tupdesc -> attrs [i ]-> attname ),
368+ if (relkind != RELKIND_VIEW )
369+ for (i = 0 ;i < natts ;i ++ )
370+ {
371+ if (SystemAttributeByName (NameStr (tupdesc -> attrs [i ]-> attname ),
371372relhasoids )!= NULL )
372- elog (ERROR ,"name of column \"%s\" conflicts with an existing system column" ,
373+ elog (ERROR ,"name of column \"%s\" conflicts with an existing system column" ,
373374NameStr (tupdesc -> attrs [i ]-> attname ));
374- if (tupdesc -> attrs [i ]-> atttypid == UNKNOWNOID )
375- elog (WARNING ,"Attribute '%s' has an unknown type"
375+ if (tupdesc -> attrs [i ]-> atttypid == UNKNOWNOID )
376+ elog (WARNING ,"Attribute '%s' has an unknown type"
376377"\n\tProceeding with relation creation anyway" ,
377378NameStr (tupdesc -> attrs [i ]-> attname ));
378- }
379+ }
379380
380381/*
381382 * next check for repeated attribute names
@@ -402,7 +403,8 @@ CheckAttributeNames(TupleDesc tupdesc, bool relhasoids)
402403static void
403404AddNewAttributeTuples (Oid new_rel_oid ,
404405TupleDesc tupdesc ,
405- bool relhasoids )
406+ bool relhasoids ,
407+ int relkind )
406408{
407409Form_pg_attribute * dpp ;
408410int i ;
@@ -453,36 +455,36 @@ AddNewAttributeTuples(Oid new_rel_oid,
453455 * next we add the system attributes. Skip OID if rel has no OIDs.
454456 */
455457dpp = SysAtt ;
456- for (i = 0 ;i < -1 - FirstLowInvalidHeapAttributeNumber ;i ++ )
457- {
458- if (relhasoids || (* dpp )-> attnum != ObjectIdAttributeNumber )
458+ if (relkind != RELKIND_VIEW )
459+ for (i = 0 ;i < -1 - FirstLowInvalidHeapAttributeNumber ;i ++ )
459460{
460- Form_pg_attribute attStruct ;
461+ if (relhasoids || (* dpp )-> attnum != ObjectIdAttributeNumber )
462+ {
463+ Form_pg_attribute attStruct ;
461464
462- tup = heap_addheader (Natts_pg_attribute ,
465+ tup = heap_addheader (Natts_pg_attribute ,
463466ATTRIBUTE_TUPLE_SIZE ,
464467 (void * )* dpp );
465468
466- /* Fill in the correct relation OID in the copied tuple */
467- attStruct = (Form_pg_attribute )GETSTRUCT (tup );
468- attStruct -> attrelid = new_rel_oid ;
469+ /* Fill in the correct relation OID in the copied tuple */
470+ attStruct = (Form_pg_attribute )GETSTRUCT (tup );
471+ attStruct -> attrelid = new_rel_oid ;
469472
470- /*
471- * Unneeded since they should be OK in the constant data
472- * anyway
473- */
474- /* attStruct->attstattarget = 0; */
475- /* attStruct->attcacheoff = -1; */
473+ /*
474+ * Unneeded since they should be OK in the constant data
475+ * anyway
476+ */
477+ /* attStruct->attstattarget = 0; */
478+ /* attStruct->attcacheoff = -1; */
476479
477- simple_heap_insert (rel ,tup );
480+ simple_heap_insert (rel ,tup );
478481
479- if (hasindex )
480- CatalogIndexInsert (idescs ,Num_pg_attr_indices ,rel ,tup );
482+ if (hasindex )
483+ CatalogIndexInsert (idescs ,Num_pg_attr_indices ,rel ,tup );
481484
482- heap_freetuple (tup );
485+ heap_freetuple (tup );
486+ }
483487}
484- dpp ++ ;
485- }
486488
487489/*
488490 * close pg_attribute indices
@@ -664,7 +666,7 @@ heap_create_with_catalog(const char *relname,
664666elog (ERROR ,"Number of columns is out of range (1 to %d)" ,
665667MaxHeapAttributeNumber );
666668
667- CheckAttributeNames (tupdesc ,relhasoids );
669+ CheckAttributeNames (tupdesc ,relhasoids , relkind );
668670
669671if (get_relname_relid (relname ,relnamespace ))
670672elog (ERROR ,"Relation '%s' already exists" ,relname );
@@ -717,7 +719,7 @@ heap_create_with_catalog(const char *relname,
717719 * now add tuples to pg_attribute for the attributes in our new
718720 * relation.
719721 */
720- AddNewAttributeTuples (new_rel_oid ,new_rel_desc -> rd_att ,relhasoids );
722+ AddNewAttributeTuples (new_rel_oid ,new_rel_desc -> rd_att ,relhasoids , relkind );
721723
722724/*
723725 * store constraints and defaults passed in the tupdesc, if any.