1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-11 12:22:51 +03:00

Make sure that GROUP BY terms select input column names in preference to

output column names, in compliance with the SQL standard.
Ticket [1c69be2dafc28].

FossilOrigin-Name: f2d175f975cd0be63425424ec322a98fb650019e
This commit is contained in:
drh
2013-08-15 22:40:21 +00:00
parent e35463b312
commit 0af16ab2c2
4 changed files with 74 additions and 16 deletions

View File

@@ -1043,14 +1043,16 @@ static int resolveOrderGroupBy(
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
Expr *pE = pItem->pExpr;
Expr *pE2 = sqlite3ExprSkipCollate(pE);
iCol = resolveAsName(pParse, pSelect->pEList, pE2);
if( iCol>0 ){
/* If an AS-name match is found, mark this ORDER BY column as being
** a copy of the iCol-th result-set column. The subsequent call to
** sqlite3ResolveOrderGroupBy() will convert the expression to a
** copy of the iCol-th result-set expression. */
pItem->iOrderByCol = (u16)iCol;
continue;
if( zType[0]!='G' ){
iCol = resolveAsName(pParse, pSelect->pEList, pE2);
if( iCol>0 ){
/* If an AS-name match is found, mark this ORDER BY column as being
** a copy of the iCol-th result-set column. The subsequent call to
** sqlite3ResolveOrderGroupBy() will convert the expression to a
** copy of the iCol-th result-set expression. */
pItem->iOrderByCol = (u16)iCol;
continue;
}
}
if( sqlite3ExprIsInteger(pE2, &iCol) ){
/* The ORDER BY term is an integer constant. Again, set the column