aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes/outfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-10-05 19:11:39 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-10-05 19:11:39 +0000
commit05e3d0ee8666b74f11ffad16f46e372459d6e53e (patch)
treeb273892bfda60f6bad315e84aaa2e9826e226931 /src/backend/nodes/outfuncs.c
parent5292637f52c6db8a22f99177f228273cb69fc510 (diff)
downloadpostgresql-05e3d0ee8666b74f11ffad16f46e372459d6e53e.tar.gz
postgresql-05e3d0ee8666b74f11ffad16f46e372459d6e53e.zip
Reimplementation of UNION/INTERSECT/EXCEPT. INTERSECT/EXCEPT now meet the
SQL92 semantics, including support for ALL option. All three can be used in subqueries and views. DISTINCT and ORDER BY work now in views, too. This rewrite fixes many problems with cross-datatype UNIONs and INSERT/SELECT where the SELECT yields different datatypes than the INSERT needs. I did that by making UNION subqueries and SELECT in INSERT be treated like subselects-in-FROM, thereby allowing an extra level of targetlist where the datatype conversions can be inserted safely. INITDB NEEDED!
Diffstat (limited to 'src/backend/nodes/outfuncs.c')
-rw-r--r--src/backend/nodes/outfuncs.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 39bc497343b..cf8c90ecad6 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.127 2000/09/29 18:21:29 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.128 2000/10/05 19:11:27 tgl Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -147,6 +147,7 @@ _outIndexStmt(StringInfo str, IndexStmt *node)
static void
_outSelectStmt(StringInfo str, SelectStmt *node)
{
+ /* XXX this is pretty durn incomplete */
appendStringInfo(str, "SELECT :where ");
_outNode(str, node->whereClause);
}
@@ -258,11 +259,10 @@ _outQuery(StringInfo str, Query *node)
_outToken(str, node->into);
appendStringInfo(str, " :isPortal %s :isBinary %s :isTemp %s"
- " :unionall %s :hasAggs %s :hasSubLinks %s :rtable ",
+ " :hasAggs %s :hasSubLinks %s :rtable ",
node->isPortal ? "true" : "false",
node->isBinary ? "true" : "false",
node->isTemp ? "true" : "false",
- node->unionall ? "true" : "false",
node->hasAggs ? "true" : "false",
node->hasSubLinks ? "true" : "false");
_outNode(str, node->rtable);
@@ -270,17 +270,11 @@ _outQuery(StringInfo str, Query *node)
appendStringInfo(str, " :jointree ");
_outNode(str, node->jointree);
- appendStringInfo(str, " :targetList ");
- _outNode(str, node->targetList);
-
appendStringInfo(str, " :rowMarks ");
_outIntList(str, node->rowMarks);
- appendStringInfo(str, " :distinctClause ");
- _outNode(str, node->distinctClause);
-
- appendStringInfo(str, " :sortClause ");
- _outNode(str, node->sortClause);
+ appendStringInfo(str, " :targetList ");
+ _outNode(str, node->targetList);
appendStringInfo(str, " :groupClause ");
_outNode(str, node->groupClause);
@@ -288,17 +282,20 @@ _outQuery(StringInfo str, Query *node)
appendStringInfo(str, " :havingQual ");
_outNode(str, node->havingQual);
- appendStringInfo(str, " :intersectClause ");
- _outNode(str, node->intersectClause);
+ appendStringInfo(str, " :distinctClause ");
+ _outNode(str, node->distinctClause);
- appendStringInfo(str, " :unionClause ");
- _outNode(str, node->unionClause);
+ appendStringInfo(str, " :sortClause ");
+ _outNode(str, node->sortClause);
appendStringInfo(str, " :limitOffset ");
_outNode(str, node->limitOffset);
appendStringInfo(str, " :limitCount ");
_outNode(str, node->limitCount);
+
+ appendStringInfo(str, " :setOperations ");
+ _outNode(str, node->setOperations);
}
static void
@@ -315,6 +312,19 @@ _outGroupClause(StringInfo str, GroupClause *node)
node->tleSortGroupRef, node->sortop);
}
+static void
+_outSetOperationStmt(StringInfo str, SetOperationStmt *node)
+{
+ appendStringInfo(str, " SETOPERATIONSTMT :op %d :all %s :larg ",
+ (int) node->op,
+ node->all ? "true" : "false");
+ _outNode(str, node->larg);
+ appendStringInfo(str, " :rarg ");
+ _outNode(str, node->rarg);
+ appendStringInfo(str, " :colTypes ");
+ _outIntList(str, node->colTypes);
+}
+
/*
* print the basic stuff of all nodes that inherit from Plan
*/
@@ -384,11 +394,7 @@ _outAppend(StringInfo str, Append *node)
appendStringInfo(str, " :appendplans ");
_outNode(str, node->appendplans);
- appendStringInfo(str, " :unionrtables ");
- _outNode(str, node->unionrtables);
-
- appendStringInfo(str,
- " :inheritrelid %u :inheritrtable ",
+ appendStringInfo(str, " :inheritrelid %u :inheritrtable ",
node->inheritrelid);
_outNode(str, node->inheritrtable);
}
@@ -601,6 +607,22 @@ _outUnique(StringInfo str, Unique *node)
appendStringInfo(str, "%d ", (int) node->uniqColIdx[i]);
}
+static void
+_outSetOp(StringInfo str, SetOp *node)
+{
+ int i;
+
+ appendStringInfo(str, " SETOP ");
+ _outPlanInfo(str, (Plan *) node);
+
+ appendStringInfo(str, " :cmd %d :numCols %d :dupColIdx ",
+ (int) node->cmd, node->numCols);
+ for (i = 0; i < node->numCols; i++)
+ appendStringInfo(str, "%d ", (int) node->dupColIdx[i]);
+ appendStringInfo(str, " :flagColIdx %d ",
+ (int) node->flagColIdx);
+}
+
/*
* Hash is a subclass of Plan
*/
@@ -1480,6 +1502,9 @@ _outNode(StringInfo str, void *obj)
case T_GroupClause:
_outGroupClause(str, obj);
break;
+ case T_SetOperationStmt:
+ _outSetOperationStmt(str, obj);
+ break;
case T_Plan:
_outPlan(str, obj);
break;
@@ -1531,6 +1556,9 @@ _outNode(StringInfo str, void *obj)
case T_Unique:
_outUnique(str, obj);
break;
+ case T_SetOp:
+ _outSetOp(str, obj);
+ break;
case T_Hash:
_outHash(str, obj);
break;