* out of it's tuple
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.28 1999/10/04 04:37:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.29 1999/10/31 18:57:42 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
#include "postgres.h"
-#include "executor/spi.h"
-#include "lib/stringinfo.h"
-#include "optimizer/clauses.h"
-#include "optimizer/tlist.h"
#include "catalog/pg_index.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_shadow.h"
#include "catalog/pg_type.h"
+#include "executor/spi.h"
+#include "lib/stringinfo.h"
+#include "optimizer/clauses.h"
+#include "optimizer/tlist.h"
+#include "parser/parsetree.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
static bool check_if_rte_used_walker(Node *node,
check_if_rte_used_context *context);
+#define inherit_marker(rte) ((rte)->inh ? "*" : "")
+
/* ----------
* get_ruledef - Do it all and return a text
/* ----------
* Now check if any of the used rangetable entries is different
- * from *NEW* and *CURRENT*. If so we must omit the FROM clause
+ * from *NEW* and *CURRENT*. If so we must provide the FROM clause
* later.
* ----------
*/
quote_identifier(tle->resdom->resname));
}
- /* If we need other tables that *NEW* or *CURRENT* add the FROM clause */
+ /* If we need other tables than *NEW* or *CURRENT* add the FROM clause */
if (!rt_constonly && rt_numused > 0)
{
- appendStringInfo(buf, " FROM");
-
+ sep = " FROM ";
i = 0;
- sep = " ";
foreach(l, query->rtable)
{
if (rt_used[i++])
appendStringInfo(buf, sep);
sep = ", ";
- appendStringInfo(buf, "%s",
- quote_identifier(rte->relname));
+ appendStringInfo(buf, "%s%s",
+ quote_identifier(rte->relname),
+ inherit_marker(rte));
if (strcmp(rte->relname, rte->refname) != 0)
appendStringInfo(buf, " %s",
quote_identifier(rte->refname));
* Start the query with INSERT INTO relname
* ----------
*/
- rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
+ rte = rt_fetch(query->resultRelation, query->rtable);
appendStringInfo(buf, "INSERT INTO %s",
quote_identifier(rte->relname));
* Start the query with UPDATE relname SET
* ----------
*/
- rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
- appendStringInfo(buf, "UPDATE %s SET ",
- quote_identifier(rte->relname));
+ rte = rt_fetch(query->resultRelation, query->rtable);
+ appendStringInfo(buf, "UPDATE %s%s SET ",
+ quote_identifier(rte->relname),
+ inherit_marker(rte));
/* Add the comma separated list of 'attname = value' */
sep = "";
* Start the query with DELETE FROM relname
* ----------
*/
- rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
- appendStringInfo(buf, "DELETE FROM %s",
- quote_identifier(rte->relname));
+ rte = rt_fetch(query->resultRelation, query->rtable);
+ appendStringInfo(buf, "DELETE FROM %s%s",
+ quote_identifier(rte->relname),
+ inherit_marker(rte));
/* Add a WHERE clause if given */
if (query->qual != NULL)
while (sup-- > 0)
rtlist = lnext(rtlist);
- return (RangeTblEntry *) nth(var->varno - 1, (List *) lfirst(rtlist));
+ return rt_fetch(var->varno, (List *) lfirst(rtlist));
}