Error codes for LIMIT and OFFSET

Started by Peter Eisentrautalmost 17 years ago2 messages
#1Peter Eisentraut
peter_e@gmx.net
1 attachment(s)

I was looking into adding new specific SQL:2008 error codes for invalid
LIMIT and OFFSET values (see attached patch), when I came across an
existing error code definition:

#define ERRCODE_INVALID_LIMIT_VALUE MAKE_SQLSTATE('2','2', '0','2','0')

This definition has been in our sources since error codes were first
added, but I don't find this code in the standard (it uses a
standard-space SQLSTATE code), and as far as I can tell, it hasn't been
actually used anywhere. Except that PL/pgSQL defines it in plerrcodes.h
(and Google shows that various other interfaces list it as well), but it
can never happen, I think.

What should we do here, if anything? Redefine
ERRCODE_INVALID_LIMIT_VALUE to the new SQL:2008 code? Or remove the
whole thing (assuming that no PL/pgSQL code actually referes to it)?

Attachments:

limit-offset-errcodes.patchtext/x-diff; name=limit-offset-errcodes.patchDownload
Index: src/backend/executor/nodeLimit.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/executor/nodeLimit.c,v
retrieving revision 1.35
diff -u -3 -p -r1.35 nodeLimit.c
--- src/backend/executor/nodeLimit.c	1 Jan 2009 17:23:41 -0000	1.35
+++ src/backend/executor/nodeLimit.c	27 Feb 2009 11:23:13 -0000
@@ -247,7 +247,7 @@ recompute_limits(LimitState *node)
 			node->offset = DatumGetInt64(val);
 			if (node->offset < 0)
 				ereport(ERROR,
-						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+						(errcode(ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE),
 						 errmsg("OFFSET must not be negative")));
 		}
 	}
@@ -274,7 +274,7 @@ recompute_limits(LimitState *node)
 			node->count = DatumGetInt64(val);
 			if (node->count < 0)
 				ereport(ERROR,
-						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+						(errcode(ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE),
 						 errmsg("LIMIT must not be negative")));
 			node->noCount = false;
 		}
Index: src/include/utils/errcodes.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/utils/errcodes.h,v
retrieving revision 1.28
diff -u -3 -p -r1.28 errcodes.h
--- src/include/utils/errcodes.h	1 Jan 2009 17:24:02 -0000	1.28
+++ src/include/utils/errcodes.h	27 Feb 2009 11:23:13 -0000
@@ -136,6 +136,8 @@
 #define ERRCODE_INVALID_LIMIT_VALUE			MAKE_SQLSTATE('2','2', '0','2','0')
 #define ERRCODE_INVALID_PARAMETER_VALUE		MAKE_SQLSTATE('2','2', '0','2','3')
 #define ERRCODE_INVALID_REGULAR_EXPRESSION	MAKE_SQLSTATE('2','2', '0','1','B')
+#define ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE	MAKE_SQLSTATE('2', '2', '0', '1', 'W')
+#define ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE	MAKE_SQLSTATE('2', '2', '0', '1', 'X')
 #define ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE	MAKE_SQLSTATE('2','2', '0','0','9')
 #define ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER		MAKE_SQLSTATE('2','2', '0','0','C')
 #define ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH MAKE_SQLSTATE('2','2', '0','0','G')
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: Error codes for LIMIT and OFFSET

Peter Eisentraut <peter_e@gmx.net> writes:

What should we do here, if anything? Redefine
ERRCODE_INVALID_LIMIT_VALUE to the new SQL:2008 code?

If you're going to spell the errcode macros as suggested in the
patch, just remove ERRCODE_INVALID_LIMIT_VALUE.

Note that this patch misses at least two places where new errcodes
need to be listed (plerrcodes.h and the documentation appendix)

regards, tom lane