7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.46 1999/10/07 04:23:12 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.47 1999/10/22 11:51:35 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
31
31
static char * clauseText []= {"ORDER" ,"GROUP" };
32
32
33
33
static TargetEntry * findTargetlistEntry (ParseState * pstate ,Node * node ,
34
- List * tlist ,int clause );
34
+ List * tlist ,int clause ,
35
+ char * uniqFlag );
35
36
static void parseFromClause (ParseState * pstate ,List * frmList ,Node * * qual );
36
37
static char * transformTableEntry (ParseState * pstate ,RangeVar * r );
37
38
static List * addTargetToSortList (TargetEntry * tle ,List * sortlist ,
@@ -363,7 +364,8 @@ parseFromClause(ParseState *pstate, List *frmList, Node **qual)
363
364
* clauseidentifies clause type for error messages.
364
365
*/
365
366
static TargetEntry *
366
- findTargetlistEntry (ParseState * pstate ,Node * node ,List * tlist ,int clause )
367
+ findTargetlistEntry (ParseState * pstate ,Node * node ,List * tlist ,int clause ,
368
+ char * uniqueFlag )
367
369
{
368
370
TargetEntry * target_result = NULL ;
369
371
List * tl ;
@@ -462,6 +464,10 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
462
464
* the end of the target list. This target is set to be resjunk =
463
465
* TRUE so that it will not be projected into the final tuple.
464
466
*/
467
+ if (clause == ORDER_CLAUSE && uniqueFlag ) {
468
+ elog (ERROR ,"ORDER BY columns must appear in SELECT DISTINCT target list" );
469
+ }
470
+
465
471
target_result = transformTargetEntry (pstate ,node ,expr ,NULL , true);
466
472
lappend (tlist ,target_result );
467
473
@@ -485,7 +491,7 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
485
491
TargetEntry * tle ;
486
492
487
493
tle = findTargetlistEntry (pstate ,lfirst (gl ),
488
- targetlist ,GROUP_CLAUSE );
494
+ targetlist ,GROUP_CLAUSE , NULL );
489
495
490
496
/* avoid making duplicate grouplist entries */
491
497
if (!exprIsInSortList (tle -> expr ,glist ,targetlist ))
@@ -527,7 +533,7 @@ transformSortClause(ParseState *pstate,
527
533
TargetEntry * tle ;
528
534
529
535
tle = findTargetlistEntry (pstate ,sortby -> node ,
530
- targetlist ,ORDER_CLAUSE );
536
+ targetlist ,ORDER_CLAUSE , uniqueFlag );
531
537
532
538
sortlist = addTargetToSortList (tle ,sortlist ,targetlist ,
533
539
sortby -> useOp );