From a344a6e7b5d7b2b87f33a155c3ef88bdfdce3fd8 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Tue, 15 Feb 2000 03:38:29 +0000 Subject: Carry column aliases from the parser frontend. Enables queries like SELECT a FROM t1 tx (a); Allow join syntax, including queries like SELECT * FROM t1 NATURAL JOIN t2; Update RTE structure to hold column aliases in an Attr structure. --- src/backend/utils/adt/ruleutils.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index c4e31491604..d3c25345057 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * out of its tuple * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.39 2000/01/15 22:43:24 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.40 2000/02/15 03:37:56 thomas Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -922,9 +922,9 @@ get_select_query_def(Query *query, deparse_context *context) continue; rte = (RangeTblEntry *) lfirst(l); - if (!strcmp(rte->refname, "*NEW*")) + if (!strcmp(rte->ref->relname, "*NEW*")) continue; - if (!strcmp(rte->refname, "*CURRENT*")) + if (!strcmp(rte->ref->relname, "*CURRENT*")) continue; rt_constonly = FALSE; @@ -980,10 +980,10 @@ get_select_query_def(Query *query, deparse_context *context) { rte = (RangeTblEntry *) lfirst(l); - if (!strcmp(rte->refname, "*NEW*")) + if (!strcmp(rte->ref->relname, "*NEW*")) continue; - if (!strcmp(rte->refname, "*CURRENT*")) + if (!strcmp(rte->ref->relname, "*CURRENT*")) continue; appendStringInfo(buf, sep); @@ -991,9 +991,19 @@ get_select_query_def(Query *query, deparse_context *context) appendStringInfo(buf, "%s%s", quote_identifier(rte->relname), inherit_marker(rte)); - if (strcmp(rte->relname, rte->refname) != 0) + if (strcmp(rte->relname, rte->ref->relname) != 0) + { + List *col; appendStringInfo(buf, " %s", - quote_identifier(rte->refname)); + quote_identifier(rte->ref->relname)); + appendStringInfo(buf, " ("); + foreach (col, rte->ref->attrs) + { + if (col != lfirst(rte->ref->attrs)) + appendStringInfo(buf, ", "); + appendStringInfo(buf, "%s", strVal(col)); + } + } } } } @@ -1071,9 +1081,9 @@ get_insert_query_def(Query *query, deparse_context *context) continue; rte = (RangeTblEntry *) lfirst(l); - if (!strcmp(rte->refname, "*NEW*")) + if (!strcmp(rte->ref->relname, "*NEW*")) continue; - if (!strcmp(rte->refname, "*CURRENT*")) + if (!strcmp(rte->ref->relname, "*CURRENT*")) continue; rt_constonly = FALSE; @@ -1241,13 +1251,13 @@ get_rule_expr(Node *node, deparse_context *context) if (context->varprefix) { - if (!strcmp(rte->refname, "*NEW*")) + if (!strcmp(rte->ref->relname, "*NEW*")) appendStringInfo(buf, "new."); - else if (!strcmp(rte->refname, "*CURRENT*")) + else if (!strcmp(rte->ref->relname, "*CURRENT*")) appendStringInfo(buf, "old."); else appendStringInfo(buf, "%s.", - quote_identifier(rte->refname)); + quote_identifier(rte->ref->relname)); } appendStringInfo(buf, "%s", quote_identifier(get_attribute_name(rte->relid, -- cgit v1.2.3