On Thu, 2007-12-13 at 22:23 -0800, Neil Conway wrote: > On Thu, 2007-12-13 at 22:06 -0500, Tom Lane wrote: > > I guess that on purely philosophical grounds, it's not an unreasonable > > behavior. For example, "LIMIT n" means "output at most n tuples", > > not "output exactly n tuples". So when it outputs no tuples in the face > > of a negative limit, it's meeting its spec. > > If "LIMIT n" means "emit at most n tuples", then a query that produces 0 > rows with n < 0 is arguably violating its spec, since it has produced > more tuples than the LIMIT specified (0 > n). Interpreted this way, no > result set can be consistent with a negative limit, so I'd vote for > throwing an error.
I even found an existing, unused error message called ERRCODE_INVALID_LIMIT_VALUE so here's a patch. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com
Index: src/backend/executor/nodeLimit.c =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/backend/executor/nodeLimit.c,v retrieving revision 1.32 diff -c -r1.32 nodeLimit.c *** src/backend/executor/nodeLimit.c 15 Nov 2007 21:14:34 -0000 1.32 --- src/backend/executor/nodeLimit.c 14 Dec 2007 14:34:22 -0000 *************** *** 75,81 **** /* * Check for empty window; if so, treat like empty subplan. */ ! if (node->count <= 0 && !node->noCount) { node->lstate = LIMIT_EMPTY; return NULL; --- 75,81 ---- /* * Check for empty window; if so, treat like empty subplan. */ ! if (node->count = 0 && !node->noCount) { node->lstate = LIMIT_EMPTY; return NULL; *************** *** 246,252 **** { node->offset = DatumGetInt64(val); if (node->offset < 0) ! node->offset = 0; } } else --- 246,254 ---- { node->offset = DatumGetInt64(val); if (node->offset < 0) ! ereport(ERROR, ! (errcode(ERRCODE_INVALID_PARAMETER_VALUE), ! errmsg("OFFSET must not be negative"))); } } else *************** *** 271,277 **** { node->count = DatumGetInt64(val); if (node->count < 0) ! node->count = 0; node->noCount = false; } } --- 273,281 ---- { node->count = DatumGetInt64(val); if (node->count < 0) ! ereport(ERROR, ! (errcode(ERRCODE_INVALID_LIMIT_VALUE), ! errmsg("LIMIT must not be negative"))); node->noCount = false; } }
---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster