33 * out of it's tuple
44 *
55 * IDENTIFICATION
6- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.28 1999/10/04 04:37:23 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.29 1999/10/31 18:57:42 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
4040
4141#include "postgres.h"
4242
43- #include "executor/spi.h"
44- #include "lib/stringinfo.h"
45- #include "optimizer/clauses.h"
46- #include "optimizer/tlist.h"
4743#include "catalog/pg_index.h"
4844#include "catalog/pg_operator.h"
4945#include "catalog/pg_shadow.h"
5046#include "catalog/pg_type.h"
47+ #include "executor/spi.h"
48+ #include "lib/stringinfo.h"
49+ #include "optimizer/clauses.h"
50+ #include "optimizer/tlist.h"
51+ #include "parser/parsetree.h"
5152#include "utils/builtins.h"
5253#include "utils/lsyscache.h"
5354
@@ -112,6 +113,8 @@ static bool check_if_rte_used(Node *node, Index rt_index, int levelsup);
112113static bool check_if_rte_used_walker (Node * node ,
113114check_if_rte_used_context * context );
114115
116+ #define inherit_marker (rte ) ((rte)->inh ? "*" : "")
117+
115118
116119/* ----------
117120 * get_ruledef- Do it all and return a text
@@ -907,7 +910,7 @@ get_select_query_def(Query *query, deparse_context *context)
907910
908911/* ----------
909912 * Now check if any of the used rangetable entries is different
910- * from *NEW* and *CURRENT*. If so we mustomit the FROM clause
913+ * from *NEW* and *CURRENT*. If so we mustprovide the FROM clause
911914 * later.
912915 * ----------
913916 */
@@ -965,13 +968,11 @@ get_select_query_def(Query *query, deparse_context *context)
965968quote_identifier (tle -> resdom -> resname ));
966969}
967970
968- /* If we need other tablesthat *NEW* or *CURRENT* add the FROM clause */
971+ /* If we need other tablesthan *NEW* or *CURRENT* add the FROM clause */
969972if (!rt_constonly && rt_numused > 0 )
970973{
971- appendStringInfo (buf ," FROM" );
972-
974+ sep = " FROM " ;
973975i = 0 ;
974- sep = " " ;
975976foreach (l ,query -> rtable )
976977{
977978if (rt_used [i ++ ])
@@ -986,8 +987,9 @@ get_select_query_def(Query *query, deparse_context *context)
986987
987988appendStringInfo (buf ,sep );
988989sep = ", " ;
989- appendStringInfo (buf ,"%s" ,
990- quote_identifier (rte -> relname ));
990+ appendStringInfo (buf ,"%s%s" ,
991+ quote_identifier (rte -> relname ),
992+ inherit_marker (rte ));
991993if (strcmp (rte -> relname ,rte -> refname )!= 0 )
992994appendStringInfo (buf ," %s" ,
993995quote_identifier (rte -> refname ));
@@ -1081,7 +1083,7 @@ get_insert_query_def(Query *query, deparse_context *context)
10811083 * Start the query with INSERT INTO relname
10821084 * ----------
10831085 */
1084- rte = ( RangeTblEntry * ) nth ( query -> resultRelation - 1 ,query -> rtable );
1086+ rte = rt_fetch ( query -> resultRelation ,query -> rtable );
10851087appendStringInfo (buf ,"INSERT INTO %s" ,
10861088quote_identifier (rte -> relname ));
10871089
@@ -1134,9 +1136,10 @@ get_update_query_def(Query *query, deparse_context *context)
11341136 * Start the query with UPDATE relname SET
11351137 * ----------
11361138 */
1137- rte = (RangeTblEntry * )nth (query -> resultRelation - 1 ,query -> rtable );
1138- appendStringInfo (buf ,"UPDATE %s SET " ,
1139- quote_identifier (rte -> relname ));
1139+ rte = rt_fetch (query -> resultRelation ,query -> rtable );
1140+ appendStringInfo (buf ,"UPDATE %s%s SET " ,
1141+ quote_identifier (rte -> relname ),
1142+ inherit_marker (rte ));
11401143
11411144/* Add the comma separated list of 'attname = value' */
11421145sep = "" ;
@@ -1174,9 +1177,10 @@ get_delete_query_def(Query *query, deparse_context *context)
11741177 * Start the query with DELETE FROM relname
11751178 * ----------
11761179 */
1177- rte = (RangeTblEntry * )nth (query -> resultRelation - 1 ,query -> rtable );
1178- appendStringInfo (buf ,"DELETE FROM %s" ,
1179- quote_identifier (rte -> relname ));
1180+ rte = rt_fetch (query -> resultRelation ,query -> rtable );
1181+ appendStringInfo (buf ,"DELETE FROM %s%s" ,
1182+ quote_identifier (rte -> relname ),
1183+ inherit_marker (rte ));
11801184
11811185/* Add a WHERE clause if given */
11821186if (query -> qual != NULL )
@@ -1198,7 +1202,7 @@ get_rte_for_var(Var *var, deparse_context *context)
11981202while (sup -- > 0 )
11991203rtlist = lnext (rtlist );
12001204
1201- return ( RangeTblEntry * ) nth ( var -> varno - 1 , (List * )lfirst (rtlist ));
1205+ return rt_fetch ( var -> varno , (List * )lfirst (rtlist ));
12021206}
12031207
12041208