Skip to content

Commit 0e1bfe9

Browse files
committed
I have a patch for postgresql-snapshot(1999-10-22).
This patch fix a TODO list item. * require SELECT DISTINCT target list to have all ORDER BY columns example ogawa=> select distinct x from t1 order by y; ERROR: ORDER BY columns must appear in SELECT DISTINCT target list --- Atsushi Ogawa
1 parent 5374f3e commit 0e1bfe9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/backend/parser/parse_clause.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_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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,7 +31,8 @@
3131
static char *clauseText[] = {"ORDER", "GROUP"};
3232

3333
static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node,
34-
List *tlist, int clause);
34+
List *tlist, int clause,
35+
char *uniqFlag);
3536
static void parseFromClause(ParseState *pstate, List *frmList, Node **qual);
3637
static char *transformTableEntry(ParseState *pstate, RangeVar *r);
3738
static List *addTargetToSortList(TargetEntry *tle, List *sortlist,
@@ -363,7 +364,8 @@ parseFromClause(ParseState *pstate, List *frmList, Node **qual)
363364
* clause identifies clause type for error messages.
364365
*/
365366
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)
367369
{
368370
TargetEntry *target_result = NULL;
369371
List *tl;
@@ -462,6 +464,10 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
462464
* the end of the target list. This target is set to be resjunk =
463465
* TRUE so that it will not be projected into the final tuple.
464466
*/
467+
if(clause == ORDER_CLAUSE && uniqueFlag) {
468+
elog(ERROR, "ORDER BY columns must appear in SELECT DISTINCT target list");
469+
}
470+
465471
target_result = transformTargetEntry(pstate, node, expr, NULL, true);
466472
lappend(tlist, target_result);
467473

@@ -485,7 +491,7 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
485491
TargetEntry *tle;
486492

487493
tle = findTargetlistEntry(pstate, lfirst(gl),
488-
targetlist, GROUP_CLAUSE);
494+
targetlist, GROUP_CLAUSE, NULL);
489495

490496
/* avoid making duplicate grouplist entries */
491497
if (! exprIsInSortList(tle->expr, glist, targetlist))
@@ -527,7 +533,7 @@ transformSortClause(ParseState *pstate,
527533
TargetEntry *tle;
528534

529535
tle = findTargetlistEntry(pstate, sortby->node,
530-
targetlist, ORDER_CLAUSE);
536+
targetlist, ORDER_CLAUSE, uniqueFlag);
531537

532538
sortlist = addTargetToSortList(tle, sortlist, targetlist,
533539
sortby->useOp);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy