diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-10-06 19:51:16 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-10-06 19:51:16 +0000 |
commit | 9ea14ef56ab8b7d22a4148c4e6765a7874d968a4 (patch) | |
tree | f6005a6fb3a7fd76101c94c6951fbc814eb0f161 /src/backend/utils/adt/ruleutils.c | |
parent | fa63749d2177c3bf700f10a3d297954328ddf3bf (diff) | |
download | postgresql-9ea14ef56ab8b7d22a4148c4e6765a7874d968a4.tar.gz postgresql-9ea14ef56ab8b7d22a4148c4e6765a7874d968a4.zip |
When a function not returning RECORD has a single OUT parameter, use
the parameter's name (if any) as the default column name for SELECT FROM
the function, rather than the function name as previously. I still think
this is a bad idea, but I lost the argument. Force decompilation of
function RTEs to specify full aliases always, to reduce the odds of this
decision breaking dumped views.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index bf9ebfefaa3..1a226bd49c3 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.205 2005/08/01 20:31:12 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.206 2005/10/06 19:51:14 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -204,8 +204,8 @@ static void get_from_clause(Query *query, const char *prefix, deparse_context *context); static void get_from_clause_item(Node *jtnode, Query *query, deparse_context *context); -static void get_from_clause_alias(Alias *alias, int varno, - Query *query, deparse_context *context); +static void get_from_clause_alias(Alias *alias, RangeTblEntry *rte, + deparse_context *context); static void get_from_clause_coldeflist(List *coldeflist, deparse_context *context); static void get_opclass_name(Oid opclass, Oid actual_datatype, @@ -4113,16 +4113,15 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind); break; } + if (rte->alias != NULL) { appendStringInfo(buf, " %s", quote_identifier(rte->alias->aliasname)); gavealias = true; - if (coldeflist == NIL) - get_from_clause_alias(rte->alias, varno, query, context); } else if (rte->rtekind == RTE_RELATION && - strcmp(rte->eref->aliasname, get_rel_name(rte->relid)) != 0) + strcmp(rte->eref->aliasname, get_rel_name(rte->relid)) != 0) { /* * Apparently the rel has been renamed since the rule was @@ -4134,12 +4133,40 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) quote_identifier(rte->eref->aliasname)); gavealias = true; } + else if (rte->rtekind == RTE_FUNCTION) + { + /* + * For a function RTE, always give an alias. + * This covers possible renaming of the function and/or + * instability of the FigureColname rules for things that + * aren't simple functions. + */ + appendStringInfo(buf, " %s", + quote_identifier(rte->eref->aliasname)); + gavealias = true; + } + if (coldeflist != NIL) { if (!gavealias) appendStringInfo(buf, " AS "); get_from_clause_coldeflist(coldeflist, context); } + else + { + /* + * For a function RTE, always emit a complete column alias list; + * this is to protect against possible instability of the default + * column names (eg, from altering parameter names). Otherwise + * just report whatever the user originally gave as column + * aliases. + */ + if (rte->rtekind == RTE_FUNCTION) + get_from_clause_alias(rte->eref, rte, context); + else + get_from_clause_alias(rte->alias, rte, context); + } + } else if (IsA(jtnode, JoinExpr)) { @@ -4273,7 +4300,9 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) { appendStringInfo(buf, " %s", quote_identifier(j->alias->aliasname)); - get_from_clause_alias(j->alias, j->rtindex, query, context); + get_from_clause_alias(j->alias, + rt_fetch(j->rtindex, query->rtable), + context); } } else @@ -4287,11 +4316,10 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) * This is tricky because we must ignore dropped columns. */ static void -get_from_clause_alias(Alias *alias, int varno, - Query *query, deparse_context *context) +get_from_clause_alias(Alias *alias, RangeTblEntry *rte, + deparse_context *context) { StringInfo buf = context->buf; - RangeTblEntry *rte = rt_fetch(varno, query->rtable); ListCell *col; AttrNumber attnum; bool first = true; |