77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.45 1997/10/12 07:09:20 vadim Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.46 1997/10/16 06:58:38 vadim Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -1816,8 +1816,22 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
18161816 gl = glist = lcons (grpcl , NIL );
18171817 else
18181818 {
1819- lnext (gl ) = lcons (grpcl , NIL );
1820- gl = lnext (gl );
1819+ List * i ;
1820+
1821+ foreach (i , glist )
1822+ {
1823+ GroupClause * gcl = (GroupClause * ) lfirst (i );
1824+
1825+ if ( gcl -> entry == grpcl -> entry )
1826+ break ;
1827+ }
1828+ if ( i == NIL ) /* not in grouplist already */
1829+ {
1830+ lnext (gl ) = lcons (grpcl , NIL );
1831+ gl = lnext (gl );
1832+ }
1833+ else
1834+ pfree (grpcl ); /* get rid of this */
18211835 }
18221836 grouplist = lnext (grouplist );
18231837 }
@@ -1836,8 +1850,7 @@ transformSortClause(ParseState *pstate,
18361850 char * uniqueFlag )
18371851{
18381852 List * sortlist = NIL ;
1839- List * s = NIL ,
1840- * i ;
1853+ List * s = NIL ;
18411854
18421855 while (orderlist != NIL )
18431856 {
@@ -1860,14 +1873,30 @@ transformSortClause(ParseState *pstate,
18601873 }
18611874 else
18621875 {
1863- lnext (s ) = lcons (sortcl , NIL );
1864- s = lnext (s );
1876+ List * i ;
1877+
1878+ foreach (i , sortlist )
1879+ {
1880+ SortClause * scl = (SortClause * ) lfirst (i );
1881+
1882+ if ( scl -> resdom == sortcl -> resdom )
1883+ break ;
1884+ }
1885+ if ( i == NIL ) /* not in sortlist already */
1886+ {
1887+ lnext (s ) = lcons (sortcl , NIL );
1888+ s = lnext (s );
1889+ }
1890+ else
1891+ pfree (sortcl ); /* get rid of this */
18651892 }
18661893 orderlist = lnext (orderlist );
18671894 }
18681895
18691896 if (uniqueFlag )
18701897 {
1898+ List * i ;
1899+
18711900 if (uniqueFlag [0 ] == '*' )
18721901 {
18731902
0 commit comments