diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-09-29 18:21:41 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-09-29 18:21:41 +0000 |
commit | 3a94e789f5c9537d804210be3cb26f7fb08e3b9e (patch) | |
tree | f1eac12405e3c0ded881d7dd7e59cec35b30c335 /src/backend/parser/parse_node.c | |
parent | 6f64c2e54a0b14154a335249f4dca91a39c61c50 (diff) | |
download | postgresql-3a94e789f5c9537d804210be3cb26f7fb08e3b9e.tar.gz postgresql-3a94e789f5c9537d804210be3cb26f7fb08e3b9e.zip |
Subselects in FROM clause, per ISO syntax: FROM (SELECT ...) [AS] alias.
(Don't forget that an alias is required.) Views reimplemented as expanding
to subselect-in-FROM. Grouping, aggregates, DISTINCT in views actually
work now (he says optimistically). No UNION support in subselects/views
yet, but I have some ideas about that. Rule-related permissions checking
moved out of rewriter and into executor.
INITDB REQUIRED!
Diffstat (limited to 'src/backend/parser/parse_node.c')
-rw-r--r-- | src/backend/parser/parse_node.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c index 85a56067bd2..2ff4d9c990b 100644 --- a/src/backend/parser/parse_node.c +++ b/src/backend/parser/parse_node.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.46 2000/09/12 21:07:02 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.47 2000/09/29 18:21:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -152,11 +152,11 @@ make_op(char *opname, Node *ltree, Node *rtree) result->oper = (Node *) newop; if (!left) - result->args = lcons(right, NIL); + result->args = makeList1(right); else if (!right) - result->args = lcons(left, NIL); + result->args = makeList1(left); else - result->args = lcons(left, lcons(right, NIL)); + result->args = makeList2(left, right); return result; } /* make_op() */ @@ -171,8 +171,8 @@ make_var(ParseState *pstate, RangeTblEntry *rte, int attrno) { int vnum, sublevels_up; - Oid vartypeid; - int32 type_mod; + Oid vartypeid = 0; + int32 type_mod = 0; vnum = RTERangeTablePosn(pstate, rte, &sublevels_up); @@ -197,8 +197,22 @@ make_var(ParseState *pstate, RangeTblEntry *rte, int attrno) else { /* Subselect RTE --- get type info from subselect's tlist */ - elog(ERROR, "make_var: subselect in FROM not implemented yet"); - vartypeid = type_mod = 0; + List *tlistitem; + + foreach(tlistitem, rte->subquery->targetList) + { + TargetEntry *te = (TargetEntry *) lfirst(tlistitem); + + if (te->resdom->resjunk || te->resdom->resno != attrno) + continue; + vartypeid = te->resdom->restype; + type_mod = te->resdom->restypmod; + break; + } + /* falling off end of list shouldn't happen... */ + if (tlistitem == NIL) + elog(ERROR, "Subquery %s does not have attribute %d", + rte->eref->relname, attrno); } return makeVar(vnum, attrno, vartypeid, type_mod, sublevels_up); |