88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.43 2000/06/12 19:40:42 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.44 2000/06/20 01:41:21 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
1515#include <ctype.h>
1616
1717#include "postgres.h"
18+
1819#include "access/heapam.h"
1920#include "access/htup.h"
2021#include "catalog/pg_type.h"
2728#include "utils/lsyscache.h"
2829
2930
31+ /*
32+ * Information defining the "system" attributes of every relation.
33+ */
3034static struct
3135{
32- char * field ;
33- int code ;
36+ char * attrname ; /* name of system attribute */
37+ int attrnum ; /* its attribute number (always < 0) */
38+ Oid attrtype ; /* its type id */
3439} special_attr [] =
3540
3641{
3742 {
38- "ctid" , SelfItemPointerAttributeNumber
43+ "ctid" , SelfItemPointerAttributeNumber , TIDOID
3944 },
4045 {
41- "oid" , ObjectIdAttributeNumber
46+ "oid" , ObjectIdAttributeNumber , OIDOID
4247 },
4348 {
44- "xmin" , MinTransactionIdAttributeNumber
49+ "xmin" , MinTransactionIdAttributeNumber , XIDOID
4550 },
4651 {
47- "cmin" , MinCommandIdAttributeNumber
52+ "cmin" , MinCommandIdAttributeNumber , CIDOID
4853 },
4954 {
50- "xmax" , MaxTransactionIdAttributeNumber
55+ "xmax" , MaxTransactionIdAttributeNumber , XIDOID
5156 },
5257 {
53- "cmax" , MaxCommandIdAttributeNumber
58+ "cmax" , MaxCommandIdAttributeNumber , CIDOID
5459 },
5560};
5661
57- #define SPECIALS ((int) (sizeof(special_attr)/sizeof(* special_attr)))
62+ #define SPECIALS ((int) (sizeof(special_attr)/sizeof(special_attr[0] )))
5863
59- static char * attnum_type [SPECIALS ] = {
60- "tid" ,
61- "oid" ,
62- "xid" ,
63- "cid" ,
64- "xid" ,
65- "cid" ,
66- };
6764
6865#ifdef NOT_USED
6966/* refnameRangeTableEntries()
@@ -459,8 +456,8 @@ specialAttNum(char *a)
459456 int i ;
460457
461458 for (i = 0 ; i < SPECIALS ; i ++ )
462- if (! strcmp (special_attr [i ].field , a ))
463- return special_attr [i ].code ;
459+ if (strcmp (special_attr [i ].attrname , a ) == 0 )
460+ return special_attr [i ].attrnum ;
464461
465462 return InvalidAttrNumber ;
466463}
@@ -485,10 +482,8 @@ attnameIsSet(Relation rd, char *name)
485482 /* First check if this is a system attribute */
486483 for (i = 0 ; i < SPECIALS ; i ++ )
487484 {
488- if (!strcmp (special_attr [i ].field , name ))
489- {
485+ if (strcmp (special_attr [i ].attrname , name ) == 0 )
490486 return false; /* no sys attr is a set */
491- }
492487 }
493488 return get_attisset (RelationGetRelid (rd ), name );
494489}
@@ -516,13 +511,21 @@ attnumAttNelems(Relation rd, int attid)
516511Oid
517512attnumTypeId (Relation rd , int attid )
518513{
519-
520514 if (attid < 0 )
521- return typeTypeId (typenameType (attnum_type [- attid - 1 ]));
515+ {
516+ int i ;
517+
518+ for (i = 0 ; i < SPECIALS ; i ++ )
519+ {
520+ if (special_attr [i ].attrnum == attid )
521+ return special_attr [i ].attrtype ;
522+ }
523+ /* negative but not a valid system attr? */
524+ elog (ERROR , "attnumTypeId: bogus attribute number %d" , attid );
525+ }
522526
523527 /*
524- * -1 because varattno (where attid comes from) returns one more than
525- * index
528+ * -1 because attid is 1-based
526529 */
527530 return rd -> rd_att -> attrs [attid - 1 ]-> atttypid ;
528531}
0 commit comments