diff options
author | Marc G. Fournier <scrappy@hub.org> | 1998-08-05 04:49:19 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1998-08-05 04:49:19 +0000 |
commit | a1627a1d64da72723d61e1ff033bf00ea05a82d0 (patch) | |
tree | 4ecfc8645a11c0f0dbc118e1d6332a92c957605b /src/backend/parser/parse_target.c | |
parent | 186aeb1d671d68bb0c5f8e6d31b091add3a80f81 (diff) | |
download | postgresql-a1627a1d64da72723d61e1ff033bf00ea05a82d0.tar.gz postgresql-a1627a1d64da72723d61e1ff033bf00ea05a82d0.zip |
From: David Hartwig <daybee@bellatlantic.net>
I have attached a patch to allow GROUP BY and/or ORDER BY function or
expressions. Note worthy items:
1. The expression or function need not be in the target list.
Example:
SELECT name FROM foo GROUP BY lower(name);
2. Simplified the grammar to use expressions only.
3. Cleaned up earlier patch in this area to make use of existing
utility functions.
3. Reduced some of the members in the SortGroupBy parse node. The
original data members were redundant with the new expression node.
(MUST do a "make clean" now)
4. Added a new parse node "JoinUsing". The JOIN USING clause was
overloading this SortGroupBy structure. With the afore mentioned
reduction of members, the two clauses lost all their commonality.
5. A bug still exist where, if a function or expression is GROUPed BY,
and an aggregate function does not include a attribute from the
expression or function, the backend crashes. (or something like
that) The bug pre-dates this patch. Example:
SELECT lower(a) AS lowcase, count(b) FROM foo GROUP BY lowcase;
*** BOOM ***
--Also when not in target list
SELECT count(b) FROM foo GROUP BY lower(a);
*** BOOM AGAIN ***
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r-- | src/backend/parser/parse_target.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 7de957935d1..58dd3a28b35 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.19 1998/07/20 19:53:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.20 1998/08/05 04:49:11 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -32,11 +32,7 @@ static List *ExpandAllTables(ParseState *pstate); static char *FigureColname(Node *expr, Node *resval); -static TargetEntry * -MakeTargetlistExpr(ParseState *pstate, - char *colname, - Node *expr, - List *arrayRef); + Node * SizeTargetExpr(ParseState *pstate, Node *expr, @@ -129,7 +125,7 @@ printf("transformTargetIdent- transform type %d to %d\n", { expr = coerce_type(pstate, node, attrtype_id, attrtype_target); expr = transformExpr(pstate, expr, EXPR_COLUMN_FIRST); - tent = MakeTargetlistExpr(pstate, *resname, expr, FALSE); + tent = MakeTargetlistExpr(pstate, *resname, expr, FALSE, FALSE); expr = tent->expr; } else @@ -293,7 +289,7 @@ printf("transformTargetList: decode T_Expr\n"); constval->val.str = save_str; tent = MakeTargetlistExpr(pstate, res->name, (Node *) make_const(constval), - NULL); + NULL, FALSE); pfree(save_str); } else @@ -326,7 +322,7 @@ printf("transformTargetList: decode T_Expr\n"); } res->name = colname; tent = MakeTargetlistExpr(pstate, res->name, expr, - res->indirection); + res->indirection, FALSE); } break; } @@ -570,12 +566,17 @@ printf("SizeTargetExpr: no conversion function for sizing\n"); * For type mismatches between expressions and targets, use the same * techniques as for function and operator type coersion. * - thomas 1998-05-08 + * + * Added resjunk flag and made extern so that it can be use by GROUP/ + * ORDER BY a function or expersion not in the target_list + * - daveh@insightdist.com 1998-07-31 */ -static TargetEntry * +TargetEntry * MakeTargetlistExpr(ParseState *pstate, char *colname, Node *expr, - List *arrayRef) + List *arrayRef, + int16 resjunk) { Oid type_id, attrtype; @@ -698,7 +699,7 @@ printf("MakeTargetlistExpr: attrtypmod is %d\n", (int4) attrtypmod); colname, (Index) 0, (Oid) 0, - 0); + resjunk); tent = makeTargetEntry(resnode, expr); |