From 4a66f9dd54694eb4d7ecce2c7e0f0c50dfde88cd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 14 Feb 2001 21:35:07 +0000 Subject: Change scoping of table and join refnames to conform to SQL92: a JOIN clause with an alias is a and therefore hides table references appearing within it, according to the spec. This is the same as the preliminary patch I posted to pgsql-patches yesterday, plus some really grotty code in ruleutils.c to reverse-list a query tree with the correct alias name depending on context. I'd rather not have done that, but unless we want to force another initdb for 7.1, there's no other way for now. --- src/backend/parser/parse_node.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/backend/parser/parse_node.c') diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c index afe8ae1b801..36e43166aa9 100644 --- a/src/backend/parser/parse_node.c +++ b/src/backend/parser/parse_node.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.51 2001/01/24 19:43:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.52 2001/02/14 21:35:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -229,20 +229,22 @@ make_var(ParseState *pstate, RangeTblEntry *rte, int attrno) * * pstate Parse state * arrayBase Already-transformed expression for the array as a whole + * (may be NULL if we are handling an INSERT) + * arrayType OID of array's datatype * indirection Untransformed list of subscripts (must not be NIL) * forceSlice If true, treat subscript as array slice in all cases * assignFrom NULL for array fetch, else transformed expression for source. */ -ArrayRef * +ArrayRef * transformArraySubscripts(ParseState *pstate, Node *arrayBase, + Oid arrayType, List *indirection, bool forceSlice, Node *assignFrom) { - Oid typearray, - typeelement, - typeresult; + Oid elementType, + resultType; HeapTuple type_tuple_array, type_tuple_element; Form_pg_type type_struct_array, @@ -254,28 +256,26 @@ transformArraySubscripts(ParseState *pstate, ArrayRef *aref; /* Get the type tuple for the array */ - typearray = exprType(arrayBase); - type_tuple_array = SearchSysCache(TYPEOID, - ObjectIdGetDatum(typearray), + ObjectIdGetDatum(arrayType), 0, 0, 0); if (!HeapTupleIsValid(type_tuple_array)) elog(ERROR, "transformArraySubscripts: Cache lookup failed for array type %u", - typearray); + arrayType); type_struct_array = (Form_pg_type) GETSTRUCT(type_tuple_array); - typeelement = type_struct_array->typelem; - if (typeelement == InvalidOid) + elementType = type_struct_array->typelem; + if (elementType == InvalidOid) elog(ERROR, "transformArraySubscripts: type %s is not an array", NameStr(type_struct_array->typname)); /* Get the type tuple for the array element type */ type_tuple_element = SearchSysCache(TYPEOID, - ObjectIdGetDatum(typeelement), + ObjectIdGetDatum(elementType), 0, 0, 0); if (!HeapTupleIsValid(type_tuple_element)) elog(ERROR, "transformArraySubscripts: Cache lookup failed for array element type %u", - typeelement); + elementType); type_struct_element = (Form_pg_type) GETSTRUCT(type_tuple_element); /* @@ -308,9 +308,9 @@ transformArraySubscripts(ParseState *pstate, * array type if we are fetching a slice or storing. */ if (isSlice || assignFrom != NULL) - typeresult = typearray; + resultType = arrayType; else - typeresult = typeelement; + resultType = elementType; /* * Transform the subscript expressions. @@ -359,7 +359,7 @@ transformArraySubscripts(ParseState *pstate, if (assignFrom != NULL) { Oid typesource = exprType(assignFrom); - Oid typeneeded = isSlice ? typearray : typeelement; + Oid typeneeded = isSlice ? arrayType : elementType; if (typesource != InvalidOid) { @@ -385,7 +385,7 @@ transformArraySubscripts(ParseState *pstate, aref = makeNode(ArrayRef); aref->refattrlength = type_struct_array->typlen; aref->refelemlength = type_struct_element->typlen; - aref->refelemtype = typeresult; /* XXX should save element type + aref->refelemtype = resultType; /* XXX should save element type * too */ aref->refelembyval = type_struct_element->typbyval; aref->refupperindexpr = upperIndexpr; -- cgit v1.2.3