8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.128 2004/04/18 18:12:57 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.129 2004/05/23 17:10:54 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -58,7 +58,7 @@ static Node *transformFromClauseItem(ParseState *pstate, Node *n,
58
58
static Node * buildMergedJoinVar (ParseState * pstate , JoinType jointype ,
59
59
Var * l_colvar , Var * r_colvar );
60
60
static TargetEntry * findTargetlistEntry (ParseState * pstate , Node * node ,
61
- List * tlist , int clause );
61
+ List * * tlist , int clause );
62
62
63
63
64
64
/*
@@ -1076,12 +1076,11 @@ transformLimitClause(ParseState *pstate, Node *clause,
1076
1076
* list as a "resjunk" node.
1077
1077
*
1078
1078
* node the ORDER BY, GROUP BY, or DISTINCT ON expression to be matched
1079
- * tlist the existing target list (NB: this will never be NIL, which is a
1080
- * good thing since we'd be unable to append to it if it were...)
1081
- * clause identifies clause type being processed.
1079
+ * tlist the target list (passed by reference so we can append to it)
1080
+ * clause identifies clause type being processed
1082
1081
*/
1083
1082
static TargetEntry *
1084
- findTargetlistEntry (ParseState * pstate , Node * node , List * tlist , int clause )
1083
+ findTargetlistEntry (ParseState * pstate , Node * node , List * * tlist , int clause )
1085
1084
{
1086
1085
TargetEntry * target_result = NULL ;
1087
1086
List * tl ;
@@ -1157,7 +1156,7 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
1157
1156
1158
1157
if (name != NULL )
1159
1158
{
1160
- foreach (tl , tlist )
1159
+ foreach (tl , * tlist )
1161
1160
{
1162
1161
TargetEntry * tle = (TargetEntry * ) lfirst (tl );
1163
1162
Resdom * resnode = tle -> resdom ;
@@ -1196,7 +1195,7 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
1196
1195
errmsg ("non-integer constant in %s" ,
1197
1196
clauseText [clause ])));
1198
1197
target_pos = intVal (val );
1199
- foreach (tl , tlist )
1198
+ foreach (tl , * tlist )
1200
1199
{
1201
1200
TargetEntry * tle = (TargetEntry * ) lfirst (tl );
1202
1201
Resdom * resnode = tle -> resdom ;
@@ -1224,7 +1223,7 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
1224
1223
*/
1225
1224
expr = transformExpr (pstate , node );
1226
1225
1227
- foreach (tl , tlist )
1226
+ foreach (tl , * tlist )
1228
1227
{
1229
1228
TargetEntry * tle = (TargetEntry * ) lfirst (tl );
1230
1229
@@ -1238,7 +1237,8 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
1238
1237
* that it will not be projected into the final tuple.
1239
1238
*/
1240
1239
target_result = transformTargetEntry (pstate , node , expr , NULL , true);
1241
- lappend (tlist , target_result );
1240
+
1241
+ * tlist = lappend (* tlist , target_result );
1242
1242
1243
1243
return target_result ;
1244
1244
}
@@ -1247,10 +1247,13 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
1247
1247
/*
1248
1248
* transformGroupClause -
1249
1249
* transform a GROUP BY clause
1250
+ *
1251
+ * GROUP BY items will be added to the targetlist (as resjunk columns)
1252
+ * if not already present, so the targetlist must be passed by reference.
1250
1253
*/
1251
1254
List *
1252
1255
transformGroupClause (ParseState * pstate , List * grouplist ,
1253
- List * targetlist , List * sortClause )
1256
+ List * * targetlist , List * sortClause )
1254
1257
{
1255
1258
List * glist = NIL ,
1256
1259
* gl ;
@@ -1304,7 +1307,7 @@ transformGroupClause(ParseState *pstate, List *grouplist,
1304
1307
}
1305
1308
1306
1309
grpcl = makeNode (GroupClause );
1307
- grpcl -> tleSortGroupRef = assignSortGroupRef (tle , targetlist );
1310
+ grpcl -> tleSortGroupRef = assignSortGroupRef (tle , * targetlist );
1308
1311
grpcl -> sortop = ordering_op ;
1309
1312
glist = lappend (glist , grpcl );
1310
1313
}
@@ -1315,11 +1318,14 @@ transformGroupClause(ParseState *pstate, List *grouplist,
1315
1318
/*
1316
1319
* transformSortClause -
1317
1320
* transform an ORDER BY clause
1321
+ *
1322
+ * ORDER BY items will be added to the targetlist (as resjunk columns)
1323
+ * if not already present, so the targetlist must be passed by reference.
1318
1324
*/
1319
1325
List *
1320
1326
transformSortClause (ParseState * pstate ,
1321
1327
List * orderlist ,
1322
- List * targetlist ,
1328
+ List * * targetlist ,
1323
1329
bool resolveUnknown )
1324
1330
{
1325
1331
List * sortlist = NIL ;
@@ -1334,7 +1340,7 @@ transformSortClause(ParseState *pstate,
1334
1340
targetlist , ORDER_CLAUSE );
1335
1341
1336
1342
sortlist = addTargetToSortList (pstate , tle ,
1337
- sortlist , targetlist ,
1343
+ sortlist , * targetlist ,
1338
1344
sortby -> sortby_kind ,
1339
1345
sortby -> useOp ,
1340
1346
resolveUnknown );
@@ -1348,13 +1354,11 @@ transformSortClause(ParseState *pstate,
1348
1354
* transform a DISTINCT or DISTINCT ON clause
1349
1355
*
1350
1356
* Since we may need to add items to the query's sortClause list, that list
1351
- * is passed by reference. We might also need to add items to the query's
1352
- * targetlist, but we assume that cannot be empty initially, so we can
1353
- * lappend to it even though the pointer is passed by value.
1357
+ * is passed by reference. Likewise for the targetlist.
1354
1358
*/
1355
1359
List *
1356
1360
transformDistinctClause (ParseState * pstate , List * distinctlist ,
1357
- List * targetlist , List * * sortClause )
1361
+ List * * targetlist , List * * sortClause )
1358
1362
{
1359
1363
List * result = NIL ;
1360
1364
List * slitem ;
@@ -1377,7 +1381,7 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
1377
1381
*/
1378
1382
* sortClause = addAllTargetsToSortList (pstate ,
1379
1383
* sortClause ,
1380
- targetlist ,
1384
+ * targetlist ,
1381
1385
true);
1382
1386
1383
1387
/*
@@ -1390,7 +1394,7 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
1390
1394
foreach (slitem , * sortClause )
1391
1395
{
1392
1396
SortClause * scl = (SortClause * ) lfirst (slitem );
1393
- TargetEntry * tle = get_sortgroupclause_tle (scl , targetlist );
1397
+ TargetEntry * tle = get_sortgroupclause_tle (scl , * targetlist );
1394
1398
1395
1399
if (tle -> resdom -> resjunk )
1396
1400
ereport (ERROR ,
@@ -1442,7 +1446,7 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
1442
1446
else
1443
1447
{
1444
1448
* sortClause = addTargetToSortList (pstate , tle ,
1445
- * sortClause , targetlist ,
1449
+ * sortClause , * targetlist ,
1446
1450
SORTBY_ASC , NIL , true);
1447
1451
1448
1452
/*
0 commit comments