aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_relation.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-06-20 01:41:22 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-06-20 01:41:22 +0000
commit996659f2556843490827eb5027b53bac4b10783d (patch)
tree54fc74b0573dd91922b7401e975013d92eb9f254 /src/backend/parser/parse_relation.c
parenta1dfaef6c6e2da34dbc808f205665a6c96362149 (diff)
downloadpostgresql-996659f2556843490827eb5027b53bac4b10783d.tar.gz
postgresql-996659f2556843490827eb5027b53bac4b10783d.zip
Fix handling of type tuple associated with a temp relation. We have
to apply the tempname->realname mapping to type name lookup as well as relation name lookup, else the type tuple will not be found when wanted. This fixes bugs like this one: create temp table foo (f1 int); select foo.f2 from foo; ERROR: Unable to locate type name 'foo' in catalog
Diffstat (limited to 'src/backend/parser/parse_relation.c')
-rw-r--r--src/backend/parser/parse_relation.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 41065c69077..cbb5f07fefa 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -8,13 +8,14 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.43 2000/06/12 19:40:42 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.44 2000/06/20 01:41:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <ctype.h>
#include "postgres.h"
+
#include "access/heapam.h"
#include "access/htup.h"
#include "catalog/pg_type.h"
@@ -27,43 +28,39 @@
#include "utils/lsyscache.h"
+/*
+ * Information defining the "system" attributes of every relation.
+ */
static struct
{
- char *field;
- int code;
+ char *attrname; /* name of system attribute */
+ int attrnum; /* its attribute number (always < 0) */
+ Oid attrtype; /* its type id */
} special_attr[] =
{
{
- "ctid", SelfItemPointerAttributeNumber
+ "ctid", SelfItemPointerAttributeNumber, TIDOID
},
{
- "oid", ObjectIdAttributeNumber
+ "oid", ObjectIdAttributeNumber, OIDOID
},
{
- "xmin", MinTransactionIdAttributeNumber
+ "xmin", MinTransactionIdAttributeNumber, XIDOID
},
{
- "cmin", MinCommandIdAttributeNumber
+ "cmin", MinCommandIdAttributeNumber, CIDOID
},
{
- "xmax", MaxTransactionIdAttributeNumber
+ "xmax", MaxTransactionIdAttributeNumber, XIDOID
},
{
- "cmax", MaxCommandIdAttributeNumber
+ "cmax", MaxCommandIdAttributeNumber, CIDOID
},
};
-#define SPECIALS ((int) (sizeof(special_attr)/sizeof(*special_attr)))
+#define SPECIALS ((int) (sizeof(special_attr)/sizeof(special_attr[0])))
-static char *attnum_type[SPECIALS] = {
- "tid",
- "oid",
- "xid",
- "cid",
- "xid",
- "cid",
-};
#ifdef NOT_USED
/* refnameRangeTableEntries()
@@ -459,8 +456,8 @@ specialAttNum(char *a)
int i;
for (i = 0; i < SPECIALS; i++)
- if (!strcmp(special_attr[i].field, a))
- return special_attr[i].code;
+ if (strcmp(special_attr[i].attrname, a) == 0)
+ return special_attr[i].attrnum;
return InvalidAttrNumber;
}
@@ -485,10 +482,8 @@ attnameIsSet(Relation rd, char *name)
/* First check if this is a system attribute */
for (i = 0; i < SPECIALS; i++)
{
- if (!strcmp(special_attr[i].field, name))
- {
+ if (strcmp(special_attr[i].attrname, name) == 0)
return false; /* no sys attr is a set */
- }
}
return get_attisset(RelationGetRelid(rd), name);
}
@@ -516,13 +511,21 @@ attnumAttNelems(Relation rd, int attid)
Oid
attnumTypeId(Relation rd, int attid)
{
-
if (attid < 0)
- return typeTypeId(typenameType(attnum_type[-attid - 1]));
+ {
+ int i;
+
+ for (i = 0; i < SPECIALS; i++)
+ {
+ if (special_attr[i].attrnum == attid)
+ return special_attr[i].attrtype;
+ }
+ /* negative but not a valid system attr? */
+ elog(ERROR, "attnumTypeId: bogus attribute number %d", attid);
+ }
/*
- * -1 because varattno (where attid comes from) returns one more than
- * index
+ * -1 because attid is 1-based
*/
return rd->rd_att->attrs[attid - 1]->atttypid;
}