*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.46 1999/10/07 04:23:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.47 1999/10/22 11:51:35 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static char *clauseText[] = {"ORDER", "GROUP"};
static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node,
- List *tlist, int clause);
+ List *tlist, int clause,
+ char *uniqFlag);
static void parseFromClause(ParseState *pstate, List *frmList, Node **qual);
static char *transformTableEntry(ParseState *pstate, RangeVar *r);
static List *addTargetToSortList(TargetEntry *tle, List *sortlist,
* clause identifies clause type for error messages.
*/
static TargetEntry *
-findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
+findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause,
+ char *uniqueFlag)
{
TargetEntry *target_result = NULL;
List *tl;
* the end of the target list. This target is set to be resjunk =
* TRUE so that it will not be projected into the final tuple.
*/
+ if(clause == ORDER_CLAUSE && uniqueFlag) {
+ elog(ERROR, "ORDER BY columns must appear in SELECT DISTINCT target list");
+ }
+
target_result = transformTargetEntry(pstate, node, expr, NULL, true);
lappend(tlist, target_result);
TargetEntry *tle;
tle = findTargetlistEntry(pstate, lfirst(gl),
- targetlist, GROUP_CLAUSE);
+ targetlist, GROUP_CLAUSE, NULL);
/* avoid making duplicate grouplist entries */
if (! exprIsInSortList(tle->expr, glist, targetlist))
TargetEntry *tle;
tle = findTargetlistEntry(pstate, sortby->node,
- targetlist, ORDER_CLAUSE);
+ targetlist, ORDER_CLAUSE, uniqueFlag);
sortlist = addTargetToSortList(tle, sortlist, targetlist,
sortby->useOp);