mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
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!
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.97 2000/09/29 18:21:29 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.98 2000/10/05 19:11:27 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Most of the read functions for plan nodes are tested. (In fact, they
|
||||
@ -109,10 +109,6 @@ _readQuery()
|
||||
token = lsptok(NULL, &length); /* get isTemp */
|
||||
local_node->isTemp = (token[0] == 't') ? true : false;
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :unionall */
|
||||
token = lsptok(NULL, &length); /* get unionall */
|
||||
local_node->unionall = (token[0] == 't') ? true : false;
|
||||
|
||||
token = lsptok(NULL, &length); /* skip the :hasAggs */
|
||||
token = lsptok(NULL, &length); /* get hasAggs */
|
||||
local_node->hasAggs = (token[0] == 't') ? true : false;
|
||||
@ -127,17 +123,11 @@ _readQuery()
|
||||
token = lsptok(NULL, &length); /* skip :jointree */
|
||||
local_node->jointree = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :targetlist */
|
||||
local_node->targetList = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :rowMarks */
|
||||
local_node->rowMarks = toIntList(nodeRead(true));
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :distinctClause */
|
||||
local_node->distinctClause = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :sortClause */
|
||||
local_node->sortClause = nodeRead(true);
|
||||
token = lsptok(NULL, &length); /* skip :targetlist */
|
||||
local_node->targetList = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :groupClause */
|
||||
local_node->groupClause = nodeRead(true);
|
||||
@ -145,11 +135,11 @@ _readQuery()
|
||||
token = lsptok(NULL, &length); /* skip :havingQual */
|
||||
local_node->havingQual = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :intersectClause */
|
||||
local_node->intersectClause = nodeRead(true);
|
||||
token = lsptok(NULL, &length); /* skip :distinctClause */
|
||||
local_node->distinctClause = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :unionClause */
|
||||
local_node->unionClause = nodeRead(true);
|
||||
token = lsptok(NULL, &length); /* skip :sortClause */
|
||||
local_node->sortClause = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :limitOffset */
|
||||
local_node->limitOffset = nodeRead(true);
|
||||
@ -157,6 +147,9 @@ _readQuery()
|
||||
token = lsptok(NULL, &length); /* skip :limitCount */
|
||||
local_node->limitCount = nodeRead(true);
|
||||
|
||||
token = lsptok(NULL, &length); /* skip :setOperations */
|
||||
local_node->setOperations = nodeRead(true);
|
||||
|
||||
return local_node;
|
||||
}
|
||||
|
||||
@ -208,6 +201,39 @@ _readGroupClause()
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _readSetOperationStmt
|
||||
* ----------------
|
||||
*/
|
||||
static SetOperationStmt *
|
||||
_readSetOperationStmt()
|
||||
{
|
||||
SetOperationStmt *local_node;
|
||||
char *token;
|
||||
int length;
|
||||
|
||||
local_node = makeNode(SetOperationStmt);
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :op */
|
||||
token = lsptok(NULL, &length); /* get op */
|
||||
local_node->op = (SetOperation) atoi(token);
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :all */
|
||||
token = lsptok(NULL, &length); /* get all */
|
||||
local_node->all = (token[0] == 't') ? true : false;
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :larg */
|
||||
local_node->larg = nodeRead(true); /* get larg */
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :rarg */
|
||||
local_node->rarg = nodeRead(true); /* get rarg */
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :colTypes */
|
||||
local_node->colTypes = toIntList(nodeRead(true));
|
||||
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _getPlan
|
||||
* ----------------
|
||||
@ -322,9 +348,6 @@ _readAppend()
|
||||
token = lsptok(NULL, &length); /* eat :appendplans */
|
||||
local_node->appendplans = nodeRead(true); /* now read it */
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :unionrtables */
|
||||
local_node->unionrtables = nodeRead(true); /* now read it */
|
||||
|
||||
token = lsptok(NULL, &length); /* eat :inheritrelid */
|
||||
token = lsptok(NULL, &length); /* get inheritrelid */
|
||||
local_node->inheritrelid = strtoul(token, NULL, 10);
|
||||
@ -1995,6 +2018,8 @@ parsePlanString(void)
|
||||
return_value = _readSortClause();
|
||||
else if (length == 11 && strncmp(token, "GROUPCLAUSE", length) == 0)
|
||||
return_value = _readGroupClause();
|
||||
else if (length == 16 && strncmp(token, "SETOPERATIONSTMT", length) == 0)
|
||||
return_value = _readSetOperationStmt();
|
||||
else if (length == 4 && strncmp(token, "CASE", length) == 0)
|
||||
return_value = _readCaseExpr();
|
||||
else if (length == 4 && strncmp(token, "WHEN", length) == 0)
|
||||
|
Reference in New Issue
Block a user