Maciej =?iso-8859-2?Q?Blizi=F1ski?= <maciej.blizinski@dobranet.polbox.pl> writes: > I started to write the query that should compute the median. > Surprisingly, I get following error message: > "server closed the connection unexpectedly Yeah, that's a bug. The patch is attached if you need it. However, I think you will wind up looking for some other way to solve the problem, because this query won't scale well to large datasets. regards, tom lane Index: setrefs.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/optimizer/plan/setrefs.c,v retrieving revision 1.97 diff -c -r1.97 setrefs.c *** setrefs.c 8 Aug 2003 21:41:50 -0000 1.97 --- setrefs.c 11 May 2004 12:45:54 -0000 *************** *** 189,195 **** case T_Sort: case T_Unique: case T_SetOp: - case T_Limit: /* * These plan types don't actually bother to evaluate their --- 189,194 ---- *************** *** 201,206 **** --- 200,214 ---- * reprocessing subplans that also appear in lower levels of * the plan tree! */ + break; + case T_Limit: + /* + * Like the plan types above, Limit doesn't evaluate its + * tlist or quals. It does have live expressions for + * limit/offset, however. + */ + fix_expr_references(plan, ((Limit *) plan)->limitOffset); + fix_expr_references(plan, ((Limit *) plan)->limitCount); break; case T_Agg: case T_Group: Index: subselect.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/optimizer/plan/subselect.c,v retrieving revision 1.83.2.1 diff -c -r1.83.2.1 subselect.c *** subselect.c 25 Nov 2003 23:59:32 -0000 1.83.2.1 --- subselect.c 11 May 2004 12:45:54 -0000 *************** *** 1018,1023 **** --- 1018,1030 ---- &context); break; + case T_Limit: + finalize_primnode(((Limit *) plan)->limitOffset, + &context); + finalize_primnode(((Limit *) plan)->limitCount, + &context); + break; + case T_Hash: finalize_primnode((Node *) ((Hash *) plan)->hashkeys, &context); *************** *** 1029,1035 **** case T_Sort: case T_Unique: case T_SetOp: - case T_Limit: case T_Group: break; --- 1036,1041 ---- ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html