8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
15
15
#include <ctype.h>
16
16
17
17
#include "postgres.h"
18
+
18
19
#include "access/heapam.h"
19
20
#include "access/htup.h"
20
21
#include "catalog/pg_type.h"
27
28
#include "utils/lsyscache.h"
28
29
29
30
31
+ /*
32
+ * Information defining the "system" attributes of every relation.
33
+ */
30
34
static struct
31
35
{
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 */
34
39
} special_attr [] =
35
40
36
41
{
37
42
{
38
- "ctid" , SelfItemPointerAttributeNumber
43
+ "ctid" , SelfItemPointerAttributeNumber , TIDOID
39
44
},
40
45
{
41
- "oid" , ObjectIdAttributeNumber
46
+ "oid" , ObjectIdAttributeNumber , OIDOID
42
47
},
43
48
{
44
- "xmin" , MinTransactionIdAttributeNumber
49
+ "xmin" , MinTransactionIdAttributeNumber , XIDOID
45
50
},
46
51
{
47
- "cmin" , MinCommandIdAttributeNumber
52
+ "cmin" , MinCommandIdAttributeNumber , CIDOID
48
53
},
49
54
{
50
- "xmax" , MaxTransactionIdAttributeNumber
55
+ "xmax" , MaxTransactionIdAttributeNumber , XIDOID
51
56
},
52
57
{
53
- "cmax" , MaxCommandIdAttributeNumber
58
+ "cmax" , MaxCommandIdAttributeNumber , CIDOID
54
59
},
55
60
};
56
61
57
- #define SPECIALS ((int) (sizeof(special_attr)/sizeof(* special_attr)))
62
+ #define SPECIALS ((int) (sizeof(special_attr)/sizeof(special_attr[0] )))
58
63
59
- static char * attnum_type [SPECIALS ] = {
60
- "tid" ,
61
- "oid" ,
62
- "xid" ,
63
- "cid" ,
64
- "xid" ,
65
- "cid" ,
66
- };
67
64
68
65
#ifdef NOT_USED
69
66
/* refnameRangeTableEntries()
@@ -459,8 +456,8 @@ specialAttNum(char *a)
459
456
int i ;
460
457
461
458
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 ;
464
461
465
462
return InvalidAttrNumber ;
466
463
}
@@ -485,10 +482,8 @@ attnameIsSet(Relation rd, char *name)
485
482
/* First check if this is a system attribute */
486
483
for (i = 0 ; i < SPECIALS ; i ++ )
487
484
{
488
- if (!strcmp (special_attr [i ].field , name ))
489
- {
485
+ if (strcmp (special_attr [i ].attrname , name ) == 0 )
490
486
return false; /* no sys attr is a set */
491
- }
492
487
}
493
488
return get_attisset (RelationGetRelid (rd ), name );
494
489
}
@@ -516,13 +511,21 @@ attnumAttNelems(Relation rd, int attid)
516
511
Oid
517
512
attnumTypeId (Relation rd , int attid )
518
513
{
519
-
520
514
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
+ }
522
526
523
527
/*
524
- * -1 because varattno (where attid comes from) returns one more than
525
- * index
528
+ * -1 because attid is 1-based
526
529
*/
527
530
return rd -> rd_att -> attrs [attid - 1 ]-> atttypid ;
528
531
}
0 commit comments