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

Commit18c3000

Browse files
committed
Teach grammar and parser about aggregate(DISTINCT ...). No implementation
yet, but at least we can give a better error message:regression=> select count(distinct f1) from int4_tbl;ERROR: aggregate(DISTINCT ...) is not implemented yetinstead of 'parser: parse error at or near distinct'.
1 parentecba5d3 commit18c3000

File tree

11 files changed

+218
-112
lines changed

11 files changed

+218
-112
lines changed

‎src/backend/nodes/outfuncs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*$Id: outfuncs.c,v 1.98 1999/11/23 20:06:53 momjian Exp $
8+
*$Id: outfuncs.c,v 1.99 1999/12/10 07:37:31 tgl Exp $
99
*
1010
* NOTES
1111
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -114,8 +114,12 @@ _outSelectStmt(StringInfo str, SelectStmt *node)
114114
staticvoid
115115
_outFuncCall(StringInfostr,FuncCall*node)
116116
{
117-
appendStringInfo(str,"FUNCTION %s :args ",stringStringInfo(node->funcname));
117+
appendStringInfo(str,"FUNCTION %s :args ",
118+
stringStringInfo(node->funcname));
118119
_outNode(str,node->args);
120+
appendStringInfo(str," :agg_star %s :agg_distinct %s ",
121+
node->agg_star ?"true" :"false",
122+
node->agg_distinct ?"true" :"false");
119123
}
120124

121125
staticvoid

‎src/backend/parser/analyze.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*$Id: analyze.c,v 1.125 1999/12/06 18:02:42 wieck Exp $
8+
*$Id: analyze.c,v 1.126 1999/12/10 07:37:35 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -624,6 +624,8 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
624624
funccallnode=makeNode(FuncCall);
625625
funccallnode->funcname="nextval";
626626
funccallnode->args=lcons(snamenode,NIL);
627+
funccallnode->agg_star= false;
628+
funccallnode->agg_distinct= false;
627629

628630
constraint=makeNode(Constraint);
629631
constraint->contype=CONSTR_DEFAULT;

‎src/backend/parser/gram.y

Lines changed: 58 additions & 11 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.120 1999/12/1005:17:13 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.121 1999/12/1007:37:35 tgl Exp $
1414
*
1515
* HISTORY
1616
* AUTHORDATEMAJOR EVENT
@@ -246,7 +246,7 @@ static Node *doNegate(Node *n);
246246
%type <str>TypeId
247247

248248
%type <node>TableConstraint
249-
%type <list>ColPrimaryKey,ColQualifier
249+
%type <list>ColPrimaryKey,ColConstraintList
250250
%type <node>ColConstraint, ColConstraintElem
251251
%type <ival>key_actions, key_action, key_reference
252252
%type <str>key_match
@@ -912,7 +912,7 @@ OptTableElement: columnDef{ $$ = $1; }
912912
| TableConstraint{ $$ = $1; }
913913
;
914914

915-
columnDef: ColId TypenameColQualifier
915+
columnDef: ColId TypenameColConstraintList
916916
{
917917
ColumnDef *n = makeNode(ColumnDef);
918918
n->colname = $1;
@@ -939,14 +939,15 @@ columnDef: ColId Typename ColQualifier
939939
}
940940
;
941941

942-
ColQualifier:ColQualifier ColConstraint
942+
ColConstraintList:ColConstraintList ColConstraint
943943
{
944944
if ($2 != NULL)
945945
$$ = lappend($1, $2);
946946
else
947947
$$ = $1;
948948
}
949-
| /*EMPTY*/{ $$ = NULL; }
949+
| /*EMPTY*/
950+
{ $$ = NIL; }
950951
;
951952

952953
ColPrimaryKey: PRIMARY KEY
@@ -3792,6 +3793,8 @@ a_expr: com_expr
37923793
FuncCall *n = makeNode(FuncCall);
37933794
n->funcname = $3->name;
37943795
n->args = lcons($1,NIL);
3796+
n->agg_star = false;
3797+
n->agg_distinct = false;
37953798
$$ = (Node *)n;
37963799
}
37973800
}
@@ -4037,6 +4040,8 @@ b_expr: com_expr
40374040
FuncCall *n = makeNode(FuncCall);
40384041
n->funcname = $3->name;
40394042
n->args = lcons($1,NIL);
4043+
n->agg_star = false;
4044+
n->agg_distinct = false;
40404045
$$ = (Node *)n;
40414046
}
40424047
}
@@ -4129,6 +4134,8 @@ com_expr: attr
41294134
FuncCall *n = makeNode(FuncCall);
41304135
n->funcname = $5->name;
41314136
n->args = lcons($3,NIL);
4137+
n->agg_star = false;
4138+
n->agg_distinct = false;
41324139
$$ = (Node *)n;
41334140
}
41344141
}
@@ -4139,13 +4146,26 @@ com_expr: attr
41394146
FuncCall *n = makeNode(FuncCall);
41404147
n->funcname = $1;
41414148
n->args = NIL;
4149+
n->agg_star = false;
4150+
n->agg_distinct = false;
41424151
$$ = (Node *)n;
41434152
}
41444153
| func_name '(' expr_list ')'
41454154
{
41464155
FuncCall *n = makeNode(FuncCall);
41474156
n->funcname = $1;
41484157
n->args = $3;
4158+
n->agg_star = false;
4159+
n->agg_distinct = false;
4160+
$$ = (Node *)n;
4161+
}
4162+
| func_name '(' DISTINCT expr_list ')'
4163+
{
4164+
FuncCall *n = makeNode(FuncCall);
4165+
n->funcname = $1;
4166+
n->args = $4;
4167+
n->agg_star = false;
4168+
n->agg_distinct = true;
41494169
$$ = (Node *)n;
41504170
}
41514171
| func_name '(' '*' ')'
@@ -4158,12 +4178,9 @@ com_expr: attr
41584178
* and there are no other aggregates in SQL92 that accept
41594179
* '*' as parameter.
41604180
*
4161-
* XXX really, the '*' ought to be transformed to some
4162-
* special construct that wouldn't be acceptable as the
4163-
* input of a non-aggregate function, in case the given
4164-
* func_name matches a plain function. This would also
4165-
* support a possible extension to let user-defined
4166-
* aggregates do something special with '*' as input.
4181+
* The FuncCall node is also marked agg_star = true,
4182+
* so that later processing can detect what the argument
4183+
* really was.
41674184
*/
41684185
FuncCall *n = makeNode(FuncCall);
41694186
A_Const *star = makeNode(A_Const);
@@ -4172,6 +4189,8 @@ com_expr: attr
41724189
star->val.val.ival = 1;
41734190
n->funcname = $1;
41744191
n->args = lcons(star, NIL);
4192+
n->agg_star = true;
4193+
n->agg_distinct = false;
41754194
$$ = (Node *)n;
41764195
}
41774196
| CURRENT_DATE
@@ -4203,6 +4222,8 @@ com_expr: attr
42034222

42044223
n->funcname = xlateSqlType("date");
42054224
n->args = lcons(s, NIL);
4225+
n->agg_star = false;
4226+
n->agg_distinct = false;
42064227

42074228
$$ = (Node *)n;
42084229
}
@@ -4226,6 +4247,8 @@ com_expr: attr
42264247

42274248
n->funcname = xlateSqlType("time");
42284249
n->args = lcons(s, NIL);
4250+
n->agg_star = false;
4251+
n->agg_distinct = false;
42294252

42304253
$$ = (Node *)n;
42314254
}
@@ -4249,6 +4272,8 @@ com_expr: attr
42494272

42504273
n->funcname = xlateSqlType("time");
42514274
n->args = lcons(s, NIL);
4275+
n->agg_star = false;
4276+
n->agg_distinct = false;
42524277

42534278
if ($3 != 0)
42544279
elog(NOTICE,"CURRENT_TIME(%d) precision not implemented; zero used instead",$3);
@@ -4275,6 +4300,8 @@ com_expr: attr
42754300

42764301
n->funcname = xlateSqlType("timestamp");
42774302
n->args = lcons(s, NIL);
4303+
n->agg_star = false;
4304+
n->agg_distinct = false;
42784305

42794306
$$ = (Node *)n;
42804307
}
@@ -4298,6 +4325,8 @@ com_expr: attr
42984325

42994326
n->funcname = xlateSqlType("timestamp");
43004327
n->args = lcons(s, NIL);
4328+
n->agg_star = false;
4329+
n->agg_distinct = false;
43014330

43024331
if ($3 != 0)
43034332
elog(NOTICE,"CURRENT_TIMESTAMP(%d) precision not implemented; zero used instead",$3);
@@ -4309,34 +4338,44 @@ com_expr: attr
43094338
FuncCall *n = makeNode(FuncCall);
43104339
n->funcname = "getpgusername";
43114340
n->args = NIL;
4341+
n->agg_star = false;
4342+
n->agg_distinct = false;
43124343
$$ = (Node *)n;
43134344
}
43144345
| USER
43154346
{
43164347
FuncCall *n = makeNode(FuncCall);
43174348
n->funcname = "getpgusername";
43184349
n->args = NIL;
4350+
n->agg_star = false;
4351+
n->agg_distinct = false;
43194352
$$ = (Node *)n;
43204353
}
43214354
| EXTRACT '(' extract_list ')'
43224355
{
43234356
FuncCall *n = makeNode(FuncCall);
43244357
n->funcname = "date_part";
43254358
n->args = $3;
4359+
n->agg_star = false;
4360+
n->agg_distinct = false;
43264361
$$ = (Node *)n;
43274362
}
43284363
| POSITION '(' position_list ')'
43294364
{
43304365
FuncCall *n = makeNode(FuncCall);
43314366
n->funcname = "strpos";
43324367
n->args = $3;
4368+
n->agg_star = false;
4369+
n->agg_distinct = false;
43334370
$$ = (Node *)n;
43344371
}
43354372
| SUBSTRING '(' substr_list ')'
43364373
{
43374374
FuncCall *n = makeNode(FuncCall);
43384375
n->funcname = "substr";
43394376
n->args = $3;
4377+
n->agg_star = false;
4378+
n->agg_distinct = false;
43404379
$$ = (Node *)n;
43414380
}
43424381
/* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
@@ -4345,27 +4384,35 @@ com_expr: attr
43454384
FuncCall *n = makeNode(FuncCall);
43464385
n->funcname = "btrim";
43474386
n->args = $4;
4387+
n->agg_star = false;
4388+
n->agg_distinct = false;
43484389
$$ = (Node *)n;
43494390
}
43504391
| TRIM '(' LEADING trim_list ')'
43514392
{
43524393
FuncCall *n = makeNode(FuncCall);
43534394
n->funcname = "ltrim";
43544395
n->args = $4;
4396+
n->agg_star = false;
4397+
n->agg_distinct = false;
43554398
$$ = (Node *)n;
43564399
}
43574400
| TRIM '(' TRAILING trim_list ')'
43584401
{
43594402
FuncCall *n = makeNode(FuncCall);
43604403
n->funcname = "rtrim";
43614404
n->args = $4;
4405+
n->agg_star = false;
4406+
n->agg_distinct = false;
43624407
$$ = (Node *)n;
43634408
}
43644409
| TRIM '(' trim_list ')'
43654410
{
43664411
FuncCall *n = makeNode(FuncCall);
43674412
n->funcname = "btrim";
43684413
n->args = $3;
4414+
n->agg_star = false;
4415+
n->agg_distinct = false;
43694416
$$ = (Node *)n;
43704417
}
43714418
| '(' SubSelect ')'

‎src/backend/parser/parse_agg.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.30 1999/12/09 05:58:54 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.31 1999/12/10 07:37:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -203,7 +203,8 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
203203

204204
Aggref*
205205
ParseAgg(ParseState*pstate,char*aggname,Oidbasetype,
206-
List*target,intprecedence)
206+
List*args,boolagg_star,boolagg_distinct,
207+
intprecedence)
207208
{
208209
HeapTupletheAggTuple;
209210
Form_pg_aggregateaggform;
@@ -242,7 +243,7 @@ ParseAgg(ParseState *pstate, char *aggname, Oid basetype,
242243
if (OidIsValid(xfn1))
243244
{
244245
basetype=aggform->aggbasetype;
245-
vartype=exprType(lfirst(target));
246+
vartype=exprType(lfirst(args));
246247
if ((basetype!=vartype)
247248
&& (!IS_BINARY_COMPATIBLE(basetype,vartype)))
248249
{
@@ -261,9 +262,17 @@ ParseAgg(ParseState *pstate, char *aggname, Oid basetype,
261262
aggref->aggname=pstrdup(aggname);
262263
aggref->basetype=aggform->aggbasetype;
263264
aggref->aggtype=fintype;
264-
aggref->target=lfirst(target);
265+
aggref->target=lfirst(args);
265266
aggref->usenulls=usenulls;
266267

268+
/*
269+
* We should store agg_star and agg_distinct into the Aggref node,
270+
* and let downstream processing deal with them. Currently, agg_star
271+
* is ignored and agg_distinct is not implemented...
272+
*/
273+
if (agg_distinct)
274+
elog(ERROR,"aggregate(DISTINCT ...) is not implemented yet");
275+
267276
pstate->p_hasAggs= true;
268277

269278
returnaggref;

‎src/backend/parser/parse_coerce.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.25 1999/11/22 17:56:20 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.26 1999/12/10 07:37:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -99,6 +99,8 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
9999

100100
n->funcname=typeTypeName(targetType);
101101
n->args=lcons(node,NIL);
102+
n->agg_star= false;
103+
n->agg_distinct= false;
102104

103105
result=transformExpr(pstate, (Node*)n,EXPR_COLUMN_FIRST);
104106

‎src/backend/parser/parse_expr.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.59 1999/11/15 02:00:10 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.60 1999/12/10 07:37:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -106,8 +106,10 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
106106
Node*lexpr=transformExpr(pstate,a->lexpr,precedence);
107107

108108
result=ParseFuncOrColumn(pstate,
109-
"nullvalue",lcons(lexpr,NIL),
110-
&pstate->p_last_resno,
109+
"nullvalue",
110+
lcons(lexpr,NIL),
111+
false, false,
112+
&pstate->p_last_resno,
111113
precedence);
112114
}
113115
break;
@@ -116,8 +118,10 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
116118
Node*lexpr=transformExpr(pstate,a->lexpr,precedence);
117119

118120
result=ParseFuncOrColumn(pstate,
119-
"nonnullvalue",lcons(lexpr,NIL),
120-
&pstate->p_last_resno,
121+
"nonnullvalue",
122+
lcons(lexpr,NIL),
123+
false, false,
124+
&pstate->p_last_resno,
121125
precedence);
122126
}
123127
break;
@@ -192,6 +196,8 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
192196
result=ParseFuncOrColumn(pstate,
193197
fn->funcname,
194198
fn->args,
199+
fn->agg_star,
200+
fn->agg_distinct,
195201
&pstate->p_last_resno,
196202
precedence);
197203
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp