diff options
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r-- | src/backend/parser/parse_target.c | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index dce6f4d01c9..7e04a947830 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.176 2010/01/02 16:57:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.177 2010/02/26 02:00:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,9 +49,9 @@ static List *ExpandAllTables(ParseState *pstate, int location); static List *ExpandIndirectionStar(ParseState *pstate, A_Indirection *ind, bool targetlist); static List *ExpandSingleTable(ParseState *pstate, RangeTblEntry *rte, - int location, bool targetlist); + int location, bool targetlist); static List *ExpandRowReference(ParseState *pstate, Node *expr, - bool targetlist); + bool targetlist); static int FigureColnameInternal(Node *node, char **name); @@ -884,12 +884,12 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, * * (e.g., SELECT emp.*, dname FROM emp, dept) * - * Note: this code is a lot like transformColumnRef; it's tempting - * to call that instead and then replace the resulting whole-row Var - * with a list of Vars. However, that would leave us with the - * RTE's selectedCols bitmap showing the whole row as needing - * select permission, as well as the individual columns. That would - * be incorrect (since columns added later shouldn't need select + * Note: this code is a lot like transformColumnRef; it's tempting to + * call that instead and then replace the resulting whole-row Var with + * a list of Vars. However, that would leave us with the RTE's + * selectedCols bitmap showing the whole row as needing select + * permission, as well as the individual columns. That would be + * incorrect (since columns added later shouldn't need select * permissions). We could try to remove the whole-row permission bit * after the fact, but duplicating code is less messy. */ @@ -897,14 +897,15 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, char *relname = NULL; RangeTblEntry *rte = NULL; int levels_up; - enum { + enum + { CRSERR_NO_RTE, CRSERR_WRONG_DB, CRSERR_TOO_MANY } crserr = CRSERR_NO_RTE; /* - * Give the PreParseColumnRefHook, if any, first shot. If it returns + * Give the PreParseColumnRefHook, if any, first shot. If it returns * non-null then we should use that expression. */ if (pstate->p_pre_columnref_hook != NULL) @@ -932,35 +933,35 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, &levels_up); break; case 4: - { - char *catname = strVal(linitial(fields)); - - /* - * We check the catalog name and then ignore it. - */ - if (strcmp(catname, get_database_name(MyDatabaseId)) != 0) { - crserr = CRSERR_WRONG_DB; + char *catname = strVal(linitial(fields)); + + /* + * We check the catalog name and then ignore it. + */ + if (strcmp(catname, get_database_name(MyDatabaseId)) != 0) + { + crserr = CRSERR_WRONG_DB; + break; + } + nspname = strVal(lsecond(fields)); + relname = strVal(lthird(fields)); + rte = refnameRangeTblEntry(pstate, nspname, relname, + cref->location, + &levels_up); break; } - nspname = strVal(lsecond(fields)); - relname = strVal(lthird(fields)); - rte = refnameRangeTblEntry(pstate, nspname, relname, - cref->location, - &levels_up); - break; - } default: crserr = CRSERR_TOO_MANY; break; } /* - * Now give the PostParseColumnRefHook, if any, a chance. - * We cheat a bit by passing the RangeTblEntry, not a Var, - * as the planned translation. (A single Var wouldn't be - * strictly correct anyway. This convention allows hooks - * that really care to know what is happening.) + * Now give the PostParseColumnRefHook, if any, a chance. We cheat a + * bit by passing the RangeTblEntry, not a Var, as the planned + * translation. (A single Var wouldn't be strictly correct anyway. + * This convention allows hooks that really care to know what is + * happening.) */ if (pstate->p_post_columnref_hook != NULL) { @@ -1111,9 +1112,9 @@ ExpandSingleTable(ParseState *pstate, RangeTblEntry *rte, NULL, &vars); /* - * Require read access to the table. This is normally redundant - * with the markVarForSelectPriv calls below, but not if the table - * has zero columns. + * Require read access to the table. This is normally redundant with + * the markVarForSelectPriv calls below, but not if the table has zero + * columns. */ rte->requiredPerms |= ACL_SELECT; @@ -1147,7 +1148,7 @@ ExpandRowReference(ParseState *pstate, Node *expr, /* * If the rowtype expression is a whole-row Var, we can expand the fields - * as simple Vars. Note: if the RTE is a relation, this case leaves us + * as simple Vars. Note: if the RTE is a relation, this case leaves us * with the RTE's selectedCols bitmap showing the whole row as needing * select permission, as well as the individual columns. However, we can * only get here for weird notations like (table.*).*, so it's not worth @@ -1165,8 +1166,8 @@ ExpandRowReference(ParseState *pstate, Node *expr, } /* - * Otherwise we have to do it the hard way. Our current implementation - * is to generate multiple copies of the expression and do FieldSelects. + * Otherwise we have to do it the hard way. Our current implementation is + * to generate multiple copies of the expression and do FieldSelects. * (This can be pretty inefficient if the expression involves nontrivial * computation :-(.) * |