Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1627a1

Browse files
committed
From: David Hartwig <daybee@bellatlantic.net>I have attached a patch to allow GROUP BY and/or ORDER BY function orexpressions. 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 existingutility functions.3. Reduced some of the members in the SortGroupBy parse node. Theoriginal 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 wasoverloading this SortGroupBy structure. With the afore mentionedreduction 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 theexpression or function, the backend crashes. (or something likethat) 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 ***
1 parent186aeb1 commita1627a1

File tree

8 files changed

+435
-195
lines changed

8 files changed

+435
-195
lines changed

‎src/backend/parser/gram.y

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.20 1998/08/04 17:37:48 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.21 1998/08/05 04:49:08 scrappy Exp $
1414
*
1515
* HISTORY
1616
* AUTHORDATEMAJOR EVENT
@@ -103,6 +103,7 @@ Oidparam_type(int t); /* used in parse_expr.c */
103103
DefElem*defelt;
104104
ParamString*param;
105105
SortGroupBy*sortgroupby;
106+
JoinUsing*joinusing;
106107
IndexElem*ielem;
107108
RangeVar*range;
108109
RelExpr*relexp;
@@ -162,7 +163,7 @@ Oidparam_type(int t); /* used in parse_expr.c */
162163
sort_clause, sortby_list, index_params, index_list, name_list,
163164
from_clause, from_list, opt_array_bounds, nest_array_bounds,
164165
expr_list, attrs, res_target_list, res_target_list2,
165-
def_list, opt_indirection, group_clause,groupby_list,TriggerFuncArgs
166+
def_list, opt_indirection, group_clause, TriggerFuncArgs
166167

167168
%type <node>func_return
168169
%type <boolean>set_opt
@@ -171,7 +172,7 @@ Oidparam_type(int t); /* used in parse_expr.c */
171172

172173
%type <list>union_clause, select_list
173174
%type <list>join_list
174-
%type <sortgroupby>
175+
%type <joinusing>
175176
join_using
176177
%type <boolean>opt_union
177178
%type <boolean>opt_table
@@ -211,7 +212,6 @@ Oidparam_type(int t); /* used in parse_expr.c */
211212
%type <node>CreateAsElement
212213
%type <value>NumericOnly, FloatOnly, IntegerOnly
213214
%type <attr>event_object, attr
214-
%type <sortgroupby>groupby
215215
%type <sortgroupby>sortby
216216
%type <ielem>index_elem, func_index
217217
%type <range>from_val
@@ -2517,28 +2517,10 @@ sortby_list: sortby{ $$ = lcons($1, NIL); }
25172517
| sortby_list ',' sortby{ $$ = lappend($1, $3); }
25182518
;
25192519

2520-
sortby: ColId OptUseOp
2520+
sortby:a_expr OptUseOp
25212521
{
25222522
$$ = makeNode(SortGroupBy);
2523-
$$->resno = 0;
2524-
$$->range = NULL;
2525-
$$->name = $1;
2526-
$$->useOp = $2;
2527-
}
2528-
| ColId '.' ColId OptUseOp
2529-
{
2530-
$$ = makeNode(SortGroupBy);
2531-
$$->resno = 0;
2532-
$$->range = $1;
2533-
$$->name = $3;
2534-
$$->useOp = $4;
2535-
}
2536-
| Iconst OptUseOp
2537-
{
2538-
$$ = makeNode(SortGroupBy);
2539-
$$->resno = $1;
2540-
$$->range = NULL;
2541-
$$->name = NULL;
2523+
$$->node = $1;
25422524
$$->useOp = $2;
25432525
}
25442526
;
@@ -2570,40 +2552,10 @@ name_list: name
25702552
{$$ = lappend($1,makeString($3)); }
25712553
;
25722554

2573-
group_clause: GROUP BYgroupby_list{ $$ = $3; }
2555+
group_clause: GROUP BYexpr_list{ $$ = $3; }
25742556
| /*EMPTY*/{ $$ = NIL; }
25752557
;
25762558

2577-
groupby_list: groupby{ $$ = lcons($1, NIL); }
2578-
| groupby_list ',' groupby{ $$ = lappend($1, $3); }
2579-
;
2580-
2581-
groupby: ColId
2582-
{
2583-
$$ = makeNode(SortGroupBy);
2584-
$$->resno = 0;
2585-
$$->range = NULL;
2586-
$$->name = $1;
2587-
$$->useOp = NULL;
2588-
}
2589-
| ColId '.' ColId
2590-
{
2591-
$$ = makeNode(SortGroupBy);
2592-
$$->resno = 0;
2593-
$$->range = $1;
2594-
$$->name = $3;
2595-
$$->useOp = NULL;
2596-
}
2597-
| Iconst
2598-
{
2599-
$$ = makeNode(SortGroupBy);
2600-
$$->resno = $1;
2601-
$$->range = NULL;
2602-
$$->name = NULL;
2603-
$$->useOp = NULL;
2604-
}
2605-
;
2606-
26072559
having_clause: HAVING a_expr
26082560
{
26092561
$$ = $2;
@@ -2688,28 +2640,33 @@ join_list: join_using{ $$ = lcons($1, NIL); }
26882640
;
26892641

26902642
join_using: ColId
2691-
{
2692-
$$ = makeNode(SortGroupBy);
2643+
/* Changed from SortGroupBy parse node to new JoinUsing node.
2644+
* SortGroupBy no longer needs these structure members.
2645+
*
2646+
* Once, acknowledged, this comment can be removed by the
2647+
* developer(s) working on the JOIN clause.
2648+
*
2649+
* - daveh@insightdist.com 1998-07-31
2650+
*/
2651+
{
2652+
$$ = makeNode(JoinUsing);
26932653
$$->resno = 0;
26942654
$$->range = NULL;
26952655
$$->name = $1;
2696-
$$->useOp = NULL;
26972656
}
26982657
| ColId '.' ColId
26992658
{
2700-
$$ = makeNode(SortGroupBy);
2659+
$$ = makeNode(JoinUsing);
27012660
$$->resno = 0;
27022661
$$->range = $1;
27032662
$$->name = $3;
2704-
$$->useOp = NULL;
27052663
}
27062664
| Iconst
27072665
{
2708-
$$ = makeNode(SortGroupBy);
2666+
$$ = makeNode(JoinUsing);
27092667
$$->resno = $1;
27102668
$$->range = NULL;
27112669
$$->name = NULL;
2712-
$$->useOp = NULL;
27132670
}
27142671
;
27152672

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp